StarDescController.cs

using System.Collections.Generic;
using System.Web.Mvc;
using CG.StarSystem.ApplicationServices;
using CG.StarSystem.Data.Models;
using System.Threading.Tasks;
using System.Net;
 
namespace CG.StarSystem.Web.Controllers
{
    public class StarDescController : Controller
    {
        private readonly IStarDescService _service;
        public StarDescController(IStarDescService service) {
            _service = service;
        }
 
        // GET: StarDesc
        public async Task<ActionResult> Index()
        {
            IList<StarDesc> stars = await _service.GetAllStarsAsync();
             
            return View(stars);
        }
        public async Task<ActionResult> Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            StarDesc star = await _service.GetStarDescriptionByIdAsync(id);
            if (star == null)
            {
                return HttpNotFound();
            }
            return View(star);
        }
 
        // GET: Notes/Create
        public ActionResult Create()
        {
            return View();
        }
 
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Create([Bind(Include = "StarName,StarSize,StarDistanceFromSun,StarGalaxyName,StarBrightness,SpectralType")] StarDesc stardesc)
        {
            if (ModelState.IsValid)
            {
                
                await _service.AddStarAsync(stardesc);
                 
                return RedirectToAction("Index");
            }
 
            return View(stardesc);
        }
        // GET: Notes/Edit/5
        public async Task<ActionResult> Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            StarDesc stardesc = await _service.GetStarDescriptionByIdAsync(id);
            if (stardesc == null)
            {
                return HttpNotFound();
            }
            return View(stardesc);
        }

_Layout.cshtml

<!DOCTYPE html>
 
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>

Index.cshtml


@using CG.StarSystem.Data.Models;
@model IEnumerable<StarDesc>
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
 
@{
ViewBag.Title = "Star System";
}
<h2>Star List</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table border="1">
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.StarName)
</th>
<th>
@Html.DisplayNameFor(model => model.StarSize)
</th>
<th>
@Html.DisplayNameFor(model => model.StarDistanceFromSun)
</th>
<th>
@Html.DisplayNameFor(model => model.StarGalaxyName)
</th>
<th>
@Html.DisplayNameFor(model => model.StarBrightness)
</th>
<th>
@Html.DisplayNameFor(model => model.SpectralType)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.StarName)
</td>
<td>
@Html.DisplayFor(modelItem => item.StarSize)
</td>
<td>
@Html.DisplayFor(modelItem => item.StarDistanceFromSun)
</td>
<td>
@Html.DisplayFor(modelItem => item.StarGalaxyName)
</td>
<td>
@Html.DisplayFor(modelItem => item.StarBrightness)
</td>
<td>
@Html.DisplayFor(modelItem => item.SpectralType)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
 
 
}
</table>