ASP – Data Entry MVC Application – Video

I have started reading the 2nd edition of the Pro ASP.NET Core MVC book and after reading the first couple of chapters, I have decided to make a video of the application in the second chapter. The code is about 80% the same, with some minor changes from my side. This is what the application does:

As far as this is a simple application, it does not do a lot, indeed. However, it took me about 1 hour to make it “running”. This is how the HomeController.cs  looks like:

using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using PartyInvites.Models;

namespace PartyInvites.Controllers
{
    public class HomeController : Controller
    {
        public ViewResult Index()
        {
            int hour = DateTime.Now.Hour;
            ViewBag.Greeting = hour < 12 ? "Good morning" : "Good afternoon";
            return View("MyView");
        }

        [HttpGet]
        public ViewResult RsvpForm()
        {
            return View();
        }

        [HttpPost]
        public ViewResult RsvpForm(GuestResponse guestResponse)
        {
            if (ModelState.IsValid)
            {
                Repository.AddResponse(guestResponse);
                return View("Thanks", guestResponse);
            }
            else
            {
                return View();
            }
        }

        public ViewResult ListResponses()
        {
            return View(Repository.Responses.Where(r => r.WillAttend == true));
        }
    }
}

This is the Repository.cs :

using System.Collections.Generic;

namespace PartyInvites.Models
{
    public class Repository
    {
        private static List<GuestResponse> responses = new List();
        public static IEnumerable Responses
        {
            get
            {
                return responses;
            }
        }

        public static void AddResponse(GuestResponse response)
        {
            responses.Add(response);
        }
    }
}

The video is available here:

C# MVC - Simple Data Entry Application

The GitHub for the whole code is here – Github.com/Vitosh/ASP/tree/master/PartyInvites

Enjoy it! 🙂