The Code for TATTARRATTAT in C# .NET

The Model

                
using Microsoft.AspNetCore.Components.Forms;

namespace TattarrattatMVC.Models
{
    public class Palindrome
    {
        public string InputWord { get; set; }

        public string RevWord { get; set; }

        public bool IsPalindrome { get; set; }

        public string Message { get; set; }
    }
}

                
            

The View

                
<div class="col">
<h5>Enter a word or phrase.</h5>
                                        
    <form class="row gy-2 gx-3" asp-action="Reverse" asp-controller="Home" method="post">
    <div class="col">
    <input asp-for="InputWord" class="form-control mb-3 mt-2" value="@Model.InputWord" placeholder="type a word or phrase" aria-label="Enter a string." />
        </div>
    <div class="col-12 d-flex align-items-start justify-content-start">
    <button id="btnSubmit" type="submit" class="btn btn-primary">Palindrome Check</button>
        </div>
    </form>
</div>

<h5 class="mt-5 border-bottom border-2">Results</h5>
<div class="col alert alert-primary">
    <p>@Html.Raw(@Model.RevWord)</p>
    <p id="results">@Html.Raw(@Model.Message)</p>
</div>
                
            

The Controller

                
namespace TattarrattatMVC.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        public IActionResult Code()
        {
            return View();
        }

        [HttpGet]
        public IActionResult Reverse()
        {
            Palindrome model = new();
            return View(model);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public IActionResult Reverse(Palindrome palindrome)
        {
            string inputWord = palindrome.InputWord;
            string revWord = "";

            for(int i = inputWord.Length - 1; i >= 0; i--)
            {
                revWord+= inputWord[i];
            }

            palindrome.RevWord = revWord;

            revWord = Regex.Replace(revWord.ToLower(), "[^a-zA-Z0-9]+", "");
            inputWord = Regex.Replace(inputWord.ToLower(), "[^a-zA-Z0-9]+", "");

            if(revWord == inputWord)
            {
                palindrome.IsPalindrome = true;
                palindrome.Message = $"<b>{palindrome.InputWord}</b> is a palidrome!";
                palindrome.RevWord = $"Your string reversed is <b>{revWord}</b>";
            }
            else
            {
                palindrome.IsPalindrome = false;
                palindrome.Message = $"<b>{palindrome.InputWord}</b> is not a palidrome.";
                palindrome.RevWord = $"Your string reversed is <b>{revWord}</b>";
            }

            return View(palindrome);
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}

                
            

This code is structured using the MVC model.

The Model

The model represents the database. It defines the database table as well as the columns. The perameters are set in the class, and translated into SQL on the server side.

The View

The view is a web page that displays the data and is the interface between the user and the applicaiton. It uses a combination of HTML, CSS, Javasctipt and C# to display the web page.

The Controller

When the view, or web page is interacted with by the user, the controller is consulted to determine the action to be taken. In this case, the user enters data in a form, and when the button is clicked, the controller executes the appropriate action determined by the code. It communicates between the model and the view. The controller also exectues any commands on the back end database as dictated by the code. In this example, the controller recieves the data entered in the form, executes the function to reverse the string entered, communicates with the database to make the designated changes, then sends the result back to the view and displays it.

Please contact me if you have any questions and/or would like to discuss my skill set and qualifications.