diff --git a/CodingEventsDemo/CodingEventsDemo.csproj b/CodingEventsDemo/CodingEventsDemo.csproj index 7f6b0bf5..12eac4f4 100644 --- a/CodingEventsDemo/CodingEventsDemo.csproj +++ b/CodingEventsDemo/CodingEventsDemo.csproj @@ -7,7 +7,6 @@ - diff --git a/CodingEventsDemo/Controllers/EventsController.cs b/CodingEventsDemo/Controllers/EventsController.cs index 48e08159..8083a654 100644 --- a/CodingEventsDemo/Controllers/EventsController.cs +++ b/CodingEventsDemo/Controllers/EventsController.cs @@ -16,9 +16,9 @@ public class EventsController : Controller // GET: // public IActionResult Index() { - ViewBag.events = EventData.GetAll(); + List events = new List(EventData.GetAll()); - return View(); + return View(events); } public IActionResult Add() @@ -53,5 +53,27 @@ public IActionResult Delete(int[] eventIds) return Redirect("/Events"); } + + [HttpGet] + [Route("Events/Edit/{eventId}")] + public IActionResult Edit(int eventId) + { + //controller code will go here + Event editingEvent = EventData.GetById(eventId); + ViewBag.eventToEdit = editingEvent; + ViewBag.title = "Edit Event " + editingEvent.Name + "(id = " + editingEvent.Id + ")"; + return View(); + } + + [HttpPost] + [Route("Events/Edit")] + public IActionResult SubmitEditEventForm(int eventId, string name, string desc) + { + //controller code will go here + Event editingEvent = EventData.GetById(eventId); + editingEvent.Name = name; + editingEvent.Description = desc; + return Redirect("/Events"); + } } } diff --git a/CodingEventsDemo/Models/Event.cs b/CodingEventsDemo/Models/Event.cs index fd754eb0..3e0442e0 100644 --- a/CodingEventsDemo/Models/Event.cs +++ b/CodingEventsDemo/Models/Event.cs @@ -7,6 +7,7 @@ public class Event { public string Name { get; set; } + //[FromForm(Name="desc")] public string Description { get; set; } public int Id { get; } @@ -22,6 +23,7 @@ public Event(string name, string description) : this() { Name = name; Description = description; + } public override string ToString() diff --git a/CodingEventsDemo/Views/Events/Add.cshtml b/CodingEventsDemo/Views/Events/Add.cshtml index 01ae3966..a8cab2c2 100644 --- a/CodingEventsDemo/Views/Events/Add.cshtml +++ b/CodingEventsDemo/Views/Events/Add.cshtml @@ -3,11 +3,14 @@
- + +
+
+ +
-
- - -
- +
diff --git a/CodingEventsDemo/Views/Events/Edit.cshtml b/CodingEventsDemo/Views/Events/Edit.cshtml new file mode 100644 index 00000000..cf004d18 --- /dev/null +++ b/CodingEventsDemo/Views/Events/Edit.cshtml @@ -0,0 +1,34 @@ +@*

@ViewBag.title

+ +
+
+ + + +
+ + + +
*@ + +

@ViewBag.title

+ +
+
+ + +
+
+ + +
+ + + +
diff --git a/CodingEventsDemo/Views/Events/Index.cshtml b/CodingEventsDemo/Views/Events/Index.cshtml index 1e0e2c12..ca4590d1 100644 --- a/CodingEventsDemo/Views/Events/Index.cshtml +++ b/CodingEventsDemo/Views/Events/Index.cshtml @@ -1,4 +1,8 @@ -

Coding Events

+@using CodingEventsDemo.Models; + +@model List + +

Coding Events

Add Event @@ -9,7 +13,7 @@ Delete Event

-@if (ViewBag.events.Count == 0) +@if (Model.Count == 0) {

No events yet!

} @@ -27,12 +31,14 @@ else Description - @foreach (var evt in ViewBag.events) + @foreach (var evt in Model) { @evt.Id @evt.Name @evt.Description + @evt.Id + Edit Event }