From f154859db8864c7c156dccd3624e344b5f21c017 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 22 Feb 2023 15:17:21 -0600
Subject: [PATCH 01/11] contains final code for views lesson
---
CodingEvents/CodingEvents.csproj | 9 +++++
CodingEvents/Controllers/EventsController.cs | 39 ++++++++++++++++++++
CodingEvents/Properties/launchSettings.json | 2 +-
CodingEvents/Views/Events/Add.cshtml | 12 ++++++
CodingEvents/Views/Events/Index.cshtml | 18 +++++++++
5 files changed, 79 insertions(+), 1 deletion(-)
create mode 100644 CodingEvents/Controllers/EventsController.cs
create mode 100644 CodingEvents/Views/Events/Add.cshtml
create mode 100644 CodingEvents/Views/Events/Index.cshtml
diff --git a/CodingEvents/CodingEvents.csproj b/CodingEvents/CodingEvents.csproj
index b775b09..dcf267a 100644
--- a/CodingEvents/CodingEvents.csproj
+++ b/CodingEvents/CodingEvents.csproj
@@ -6,4 +6,13 @@
enable
+
+ 4
+
+
+
+
+
+
+
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
new file mode 100644
index 0000000..58452cd
--- /dev/null
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+
+// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace CodingEvents.Controllers
+{
+ public class EventsController : Controller
+ {
+ static private List Events = new List();
+
+ // GET: //
+ public IActionResult Index()
+ {
+ ViewBag.events = Events;
+
+ return View();
+ }
+
+ [HttpGet]
+ public IActionResult Add()
+ {
+ return View();
+ }
+
+ [HttpPost]
+ [Route("/Events/Add")]
+ public IActionResult NewEvent(string name)
+ {
+ Events.Add(name);
+
+ return Redirect("/Events");
+ }
+ }
+}
+
diff --git a/CodingEvents/Properties/launchSettings.json b/CodingEvents/Properties/launchSettings.json
index f91f5dd..6c90c7e 100644
--- a/CodingEvents/Properties/launchSettings.json
+++ b/CodingEvents/Properties/launchSettings.json
@@ -11,7 +11,7 @@
"CodingEvents": {
"commandName": "Project",
"launchBrowser": true,
- "applicationUrl": "https://localhost:7029;http://localhost:5015",
+ "applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
diff --git a/CodingEvents/Views/Events/Add.cshtml b/CodingEvents/Views/Events/Add.cshtml
new file mode 100644
index 0000000..fc80f5d
--- /dev/null
+++ b/CodingEvents/Views/Events/Add.cshtml
@@ -0,0 +1,12 @@
+@*
+ For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+*@
+@{
+}
+
+Add Event
+
+
\ No newline at end of file
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
new file mode 100644
index 0000000..d10a2bb
--- /dev/null
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -0,0 +1,18 @@
+@*
+ For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+*@
+@{
+}
+
+Coding Events
+
+
+ Add Event
+
+
+
+ @foreach (string meeting in ViewBag.events)
+ {
+ @meeting
+ }
+
\ No newline at end of file
From b9ae4799a23e602e665b4dafcbdbfd2a83078ae9 Mon Sep 17 00:00:00 2001
From: Sally Steuterman
Date: Thu, 23 Feb 2023 14:00:19 -0600
Subject: [PATCH 02/11] Setup for Models and Model Binding
---
CodingEvents/Controllers/EventsController.cs | 6 ++--
CodingEvents/Views/Events/Add.cshtml | 9 +++++-
CodingEvents/Views/Events/Index.cshtml | 30 ++++++++++++++++----
CodingEvents/Views/Shared/_Layout.cshtml | 9 ++----
4 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
index 58452cd..ccce65a 100644
--- a/CodingEvents/Controllers/EventsController.cs
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -10,7 +10,7 @@ namespace CodingEvents.Controllers
{
public class EventsController : Controller
{
- static private List Events = new List();
+ static private Dictionary Events = new Dictionary();
// GET: //
public IActionResult Index()
@@ -28,9 +28,9 @@ public IActionResult Add()
[HttpPost]
[Route("/Events/Add")]
- public IActionResult NewEvent(string name)
+ public IActionResult NewEvent(string name, string desc = "")
{
- Events.Add(name);
+ Events.Add(name, desc);
return Redirect("/Events");
}
diff --git a/CodingEvents/Views/Events/Add.cshtml b/CodingEvents/Views/Events/Add.cshtml
index fc80f5d..942aecb 100644
--- a/CodingEvents/Views/Events/Add.cshtml
+++ b/CodingEvents/Views/Events/Add.cshtml
@@ -7,6 +7,13 @@
Add Event
\ No newline at end of file
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
index d10a2bb..26ff0cd 100644
--- a/CodingEvents/Views/Events/Index.cshtml
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -10,9 +10,27 @@
Add Event
-
- @foreach (string meeting in ViewBag.events)
- {
- @meeting
- }
-
\ No newline at end of file
+@if (ViewBag.events.Count == 0)
+{
+ No events yet!
+}
+else
+{
+
+
+
+ Name
+
+
+ Description
+
+
+ @foreach (var evt in ViewBag.events)
+ {
+
+ @evt.Key
+ @evt.Value
+
+ }
+
+}
diff --git a/CodingEvents/Views/Shared/_Layout.cshtml b/CodingEvents/Views/Shared/_Layout.cshtml
index 97c916e..62933e1 100644
--- a/CodingEvents/Views/Shared/_Layout.cshtml
+++ b/CodingEvents/Views/Shared/_Layout.cshtml
@@ -12,19 +12,14 @@
From 8c84cc4f054fab7d6f138ddcd092d12167b75977 Mon Sep 17 00:00:00 2001
From: Sally Steuterman
Date: Mon, 27 Feb 2023 10:12:39 -0600
Subject: [PATCH 03/11] Walkthrough of models chapter
---
CodingEvents/CodingEvents.csproj | 2 +
CodingEvents/Controllers/EventsController.cs | 28 ++++++++++---
CodingEvents/Data/EventData.cs | 35 ++++++++++++++++
CodingEvents/Models/Event.cs | 42 ++++++++++++++++++++
CodingEvents/Views/Events/Add.cshtml | 14 ++++---
CodingEvents/Views/Events/Delete.cshtml | 21 ++++++++++
CodingEvents/Views/Events/Index.cshtml | 12 +++++-
7 files changed, 141 insertions(+), 13 deletions(-)
create mode 100644 CodingEvents/Data/EventData.cs
create mode 100644 CodingEvents/Models/Event.cs
create mode 100644 CodingEvents/Views/Events/Delete.cshtml
diff --git a/CodingEvents/CodingEvents.csproj b/CodingEvents/CodingEvents.csproj
index dcf267a..7916200 100644
--- a/CodingEvents/CodingEvents.csproj
+++ b/CodingEvents/CodingEvents.csproj
@@ -11,8 +11,10 @@
+
+
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
index ccce65a..5e8a89a 100644
--- a/CodingEvents/Controllers/EventsController.cs
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using CodingEvents.Data;
+using CodingEvents.Models;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -10,12 +12,10 @@ namespace CodingEvents.Controllers
{
public class EventsController : Controller
{
- static private Dictionary Events = new Dictionary();
-
// GET: //
public IActionResult Index()
{
- ViewBag.events = Events;
+ ViewBag.events = EventData.GetAll();
return View();
}
@@ -28,9 +28,27 @@ public IActionResult Add()
[HttpPost]
[Route("/Events/Add")]
- public IActionResult NewEvent(string name, string desc = "")
+ public IActionResult NewEvent(Event newEvent)
+ {
+ EventData.Add(newEvent);
+
+ return Redirect("/Events");
+ }
+
+ public IActionResult Delete()
+ {
+ ViewBag.events = EventData.GetAll();
+
+ return View();
+ }
+
+ [HttpPost]
+ public IActionResult Delete(int[] eventIds)
{
- Events.Add(name, desc);
+ foreach (int eventId in eventIds)
+ {
+ EventData.Remove(eventId);
+ }
return Redirect("/Events");
}
diff --git a/CodingEvents/Data/EventData.cs b/CodingEvents/Data/EventData.cs
new file mode 100644
index 0000000..e0662a6
--- /dev/null
+++ b/CodingEvents/Data/EventData.cs
@@ -0,0 +1,35 @@
+using System;
+using CodingEvents.Models;
+
+namespace CodingEvents.Data
+{
+ public class EventData
+ {
+ static private Dictionary Events = new Dictionary();
+
+ // Fetch all the events
+ public static IEnumerable GetAll()
+ {
+ return Events.Values;
+ }
+
+ // Add a new event to my dictionary
+ public static void Add(Event newEvent)
+ {
+ Events.Add(newEvent.Id, newEvent);
+ }
+
+ // Remove an event from my dictionary
+ public static void Remove(int id)
+ {
+ Events.Remove(id);
+ }
+
+ // Fetch a specific event
+ public static Event GetById(int id)
+ {
+ return Events[id];
+ }
+ }
+}
+
diff --git a/CodingEvents/Models/Event.cs b/CodingEvents/Models/Event.cs
new file mode 100644
index 0000000..57ed41c
--- /dev/null
+++ b/CodingEvents/Models/Event.cs
@@ -0,0 +1,42 @@
+using System;
+namespace CodingEvents.Models
+{
+ public class Event
+ {
+ public string Name { get; set; }
+ public string Description { get; set; }
+
+ public int Id { get; set; }
+ static private int nextId = 1;
+
+ public Event()
+ {
+ Id = nextId;
+ nextId++;
+ }
+
+ public Event(string name, string description)
+ {
+ Name = name;
+ Description = description;
+ Id = nextId;
+ nextId++;
+ }
+
+ public override string ToString()
+ {
+ return Name;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return obj is Event @event && Id == @event.Id;
+ }
+
+ public override int GetHashCode()
+ {
+ return HashCode.Combine(Id);
+ }
+ }
+}
+
diff --git a/CodingEvents/Views/Events/Add.cshtml b/CodingEvents/Views/Events/Add.cshtml
index 942aecb..5b72ade 100644
--- a/CodingEvents/Views/Events/Add.cshtml
+++ b/CodingEvents/Views/Events/Add.cshtml
@@ -8,12 +8,14 @@
\ No newline at end of file
diff --git a/CodingEvents/Views/Events/Delete.cshtml b/CodingEvents/Views/Events/Delete.cshtml
new file mode 100644
index 0000000..1b7564c
--- /dev/null
+++ b/CodingEvents/Views/Events/Delete.cshtml
@@ -0,0 +1,21 @@
+@*
+ For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+*@
+@{
+}
+
+Delete Event
+
+
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
index 26ff0cd..8132138 100644
--- a/CodingEvents/Views/Events/Index.cshtml
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -10,6 +10,10 @@
Add Event
+
+ Delete Event
+
+
@if (ViewBag.events.Count == 0)
{
No events yet!
@@ -18,6 +22,9 @@ else
{
+
+ Id
+
Name
@@ -28,8 +35,9 @@ else
@foreach (var evt in ViewBag.events)
{
- @evt.Key
- @evt.Value
+ @evt.Id
+ @evt.Name
+ @evt.Description
}
From 2d2795c43148c0e5aa70d3adc0fa255b7024f5db Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 1 Mar 2023 13:15:54 -0600
Subject: [PATCH 04/11] vm created, views and controllers updated
---
CodingEvents/CodingEvents.csproj | 2 ++
CodingEvents/Controllers/EventsController.cs | 17 +++++++++++----
CodingEvents/Models/Event.cs | 7 +++---
CodingEvents/ViewModels/AddEventViewModel.cs | 12 ++++++++++
CodingEvents/Views/Events/Add.cshtml | 23 ++++++++------------
CodingEvents/Views/Events/Index.cshtml | 11 ++++------
6 files changed, 44 insertions(+), 28 deletions(-)
create mode 100644 CodingEvents/ViewModels/AddEventViewModel.cs
diff --git a/CodingEvents/CodingEvents.csproj b/CodingEvents/CodingEvents.csproj
index 7916200..8b352bf 100644
--- a/CodingEvents/CodingEvents.csproj
+++ b/CodingEvents/CodingEvents.csproj
@@ -12,9 +12,11 @@
+
+
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
index 5e8a89a..b9484b8 100644
--- a/CodingEvents/Controllers/EventsController.cs
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -5,6 +5,7 @@
using CodingEvents.Data;
using CodingEvents.Models;
using Microsoft.AspNetCore.Mvc;
+using CodingEvents.ViewModels;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -15,21 +16,29 @@ public class EventsController : Controller
// GET: //
public IActionResult Index()
{
- ViewBag.events = EventData.GetAll();
+ List events = new List(EventData.GetAll());
- return View();
+ return View(events);
}
[HttpGet]
public IActionResult Add()
{
- return View();
+ AddEventViewModel addEventViewModel = new AddEventViewModel();
+
+ return View(addEventViewModel);
}
[HttpPost]
[Route("/Events/Add")]
- public IActionResult NewEvent(Event newEvent)
+ public IActionResult NewEvent(AddEventViewModel addEventViewModel)
{
+ Event newEvent = new Event
+ {
+ Name = addEventViewModel.Name,
+ Description = addEventViewModel.Description
+ };
+
EventData.Add(newEvent);
return Redirect("/Events");
diff --git a/CodingEvents/Models/Event.cs b/CodingEvents/Models/Event.cs
index 57ed41c..63339e2 100644
--- a/CodingEvents/Models/Event.cs
+++ b/CodingEvents/Models/Event.cs
@@ -3,8 +3,8 @@ namespace CodingEvents.Models
{
public class Event
{
- public string Name { get; set; }
- public string Description { get; set; }
+ public string? Name { get; set; }
+ public string? Description { get; set; }
public int Id { get; set; }
static private int nextId = 1;
@@ -23,7 +23,7 @@ public Event(string name, string description)
nextId++;
}
- public override string ToString()
+ public override string? ToString()
{
return Name;
}
@@ -40,3 +40,4 @@ public override int GetHashCode()
}
}
+//added null op.
\ No newline at end of file
diff --git a/CodingEvents/ViewModels/AddEventViewModel.cs b/CodingEvents/ViewModels/AddEventViewModel.cs
new file mode 100644
index 0000000..0d20295
--- /dev/null
+++ b/CodingEvents/ViewModels/AddEventViewModel.cs
@@ -0,0 +1,12 @@
+using System;
+namespace CodingEvents.ViewModels
+{
+ public class AddEventViewModel
+ {
+ public string? Name { get; set; }
+ public string? Description { get; set; }
+ }
+}
+
+
+//added nullable operators
diff --git a/CodingEvents/Views/Events/Add.cshtml b/CodingEvents/Views/Events/Add.cshtml
index 5b72ade..765a31a 100644
--- a/CodingEvents/Views/Events/Add.cshtml
+++ b/CodingEvents/Views/Events/Add.cshtml
@@ -1,21 +1,16 @@
-@*
- For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
-*@
-@{
-}
+@using CodingEvents.ViewModels
+@model AddEventViewModel
Add Event
-
\ No newline at end of file
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
index 8132138..5290321 100644
--- a/CodingEvents/Views/Events/Index.cshtml
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -1,8 +1,5 @@
-@*
- For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
-*@
-@{
-}
+@using CodingEvents.Models
+@model List
Coding Events
@@ -14,7 +11,7 @@
Delete Event
-@if (ViewBag.events.Count == 0)
+@if (Model.Count == 0)
{
No events yet!
}
@@ -32,7 +29,7 @@ else
Description
- @foreach (var evt in ViewBag.events)
+ @foreach (var evt in Model)
{
@evt.Id
From b106add9c66c438710aa0a3f20ee1420adcb4883 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 1 Mar 2023 14:55:15 -0600
Subject: [PATCH 05/11] validation added
---
CodingEvents/Controllers/EventsController.cs | 20 +++++++++++++-------
CodingEvents/Models/Event.cs | 4 +++-
CodingEvents/ViewModels/AddEventViewModel.cs | 14 ++++++++++++--
CodingEvents/Views/Events/Add.cshtml | 11 +++++++++--
CodingEvents/Views/Events/Index.cshtml | 4 ++++
CodingEvents/Views/Shared/_Layout.cshtml | 3 +++
6 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
index b9484b8..b241fc4 100644
--- a/CodingEvents/Controllers/EventsController.cs
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -31,17 +31,23 @@ public IActionResult Add()
[HttpPost]
[Route("/Events/Add")]
- public IActionResult NewEvent(AddEventViewModel addEventViewModel)
+ public IActionResult Add(AddEventViewModel addEventViewModel)
{
- Event newEvent = new Event
+ if (ModelState.IsValid)
{
- Name = addEventViewModel.Name,
- Description = addEventViewModel.Description
- };
+ Event newEvent = new Event
+ {
+ Name = addEventViewModel.Name,
+ Description = addEventViewModel.Description,
+ ContactEmail = addEventViewModel.ContactEmail
+ };
- EventData.Add(newEvent);
+ EventData.Add(newEvent);
- return Redirect("/Events");
+ return Redirect("/Events");
+ }
+
+ return View(addEventViewModel);
}
public IActionResult Delete()
diff --git a/CodingEvents/Models/Event.cs b/CodingEvents/Models/Event.cs
index 63339e2..aafddeb 100644
--- a/CodingEvents/Models/Event.cs
+++ b/CodingEvents/Models/Event.cs
@@ -5,6 +5,7 @@ public class Event
{
public string? Name { get; set; }
public string? Description { get; set; }
+ public string? ContactEmail { get; set; }
public int Id { get; set; }
static private int nextId = 1;
@@ -15,10 +16,11 @@ public Event()
nextId++;
}
- public Event(string name, string description)
+ public Event(string name, string description, string contactEmail)
{
Name = name;
Description = description;
+ ContactEmail = contactEmail;
Id = nextId;
nextId++;
}
diff --git a/CodingEvents/ViewModels/AddEventViewModel.cs b/CodingEvents/ViewModels/AddEventViewModel.cs
index 0d20295..b0f530d 100644
--- a/CodingEvents/ViewModels/AddEventViewModel.cs
+++ b/CodingEvents/ViewModels/AddEventViewModel.cs
@@ -1,10 +1,20 @@
using System;
+using System.ComponentModel.DataAnnotations;
+
namespace CodingEvents.ViewModels
{
public class AddEventViewModel
{
- public string? Name { get; set; }
- public string? Description { get; set; }
+ [Required(ErrorMessage = "Name is required.")]
+ [StringLength(50, MinimumLength = 3, ErrorMessage = "Name must be between 3 and 50 characters.")]
+ public string? Name { get; set; }
+
+ [Required(ErrorMessage = "Please enter a description for your event.")]
+ [StringLength(500, ErrorMessage = "Description is too long!")]
+ public string? Description { get; set; }
+
+ [EmailAddress]
+ public string? ContactEmail { get; set; }
}
}
diff --git a/CodingEvents/Views/Events/Add.cshtml b/CodingEvents/Views/Events/Add.cshtml
index 765a31a..3b6b7eb 100644
--- a/CodingEvents/Views/Events/Add.cshtml
+++ b/CodingEvents/Views/Events/Add.cshtml
@@ -6,11 +6,18 @@
\ No newline at end of file
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
index 5290321..6961e51 100644
--- a/CodingEvents/Views/Events/Index.cshtml
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -28,6 +28,9 @@ else
Description
+
+ Contact Email
+
@foreach (var evt in Model)
{
@@ -35,6 +38,7 @@ else
@evt.Id
@evt.Name
@evt.Description
+ @evt.ContactEmail
}
diff --git a/CodingEvents/Views/Shared/_Layout.cshtml b/CodingEvents/Views/Shared/_Layout.cshtml
index 62933e1..9d9d7b1 100644
--- a/CodingEvents/Views/Shared/_Layout.cshtml
+++ b/CodingEvents/Views/Shared/_Layout.cshtml
@@ -28,6 +28,9 @@
@RenderBody()
+
+
+
From 20982114f2d4d82d9f801136abf92d28042cce61 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 1 Mar 2023 16:30:30 -0600
Subject: [PATCH 06/11] removed resolved comment
---
CodingEvents/Models/Event.cs | 4 +---
CodingEvents/ViewModels/AddEventViewModel.cs | 3 ---
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/CodingEvents/Models/Event.cs b/CodingEvents/Models/Event.cs
index aafddeb..6772b18 100644
--- a/CodingEvents/Models/Event.cs
+++ b/CodingEvents/Models/Event.cs
@@ -40,6 +40,4 @@ public override int GetHashCode()
return HashCode.Combine(Id);
}
}
-}
-
-//added null op.
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/CodingEvents/ViewModels/AddEventViewModel.cs b/CodingEvents/ViewModels/AddEventViewModel.cs
index b0f530d..5e657bb 100644
--- a/CodingEvents/ViewModels/AddEventViewModel.cs
+++ b/CodingEvents/ViewModels/AddEventViewModel.cs
@@ -17,6 +17,3 @@ public class AddEventViewModel
public string? ContactEmail { get; set; }
}
}
-
-
-//added nullable operators
From 8edcab47121d9b465fa64bf5ee595a995c1d38eb Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Mon, 6 Mar 2023 14:43:32 -0600
Subject: [PATCH 07/11] updates for controller and view
---
CodingEvents/Controllers/EventsController.cs | 1 -
CodingEvents/Views/Events/Index.cshtml | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
index b241fc4..49ec466 100644
--- a/CodingEvents/Controllers/EventsController.cs
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -30,7 +30,6 @@ public IActionResult Add()
}
[HttpPost]
- [Route("/Events/Add")]
public IActionResult Add(AddEventViewModel addEventViewModel)
{
if (ModelState.IsValid)
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
index 6961e51..5f61f68 100644
--- a/CodingEvents/Views/Events/Index.cshtml
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -42,4 +42,4 @@ else
}
-}
+}
\ No newline at end of file
From eacfddba7f9585dded12e2219fa88d4310bec6c7 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 8 Mar 2023 14:43:53 -0600
Subject: [PATCH 08/11] code for orm 1 added
---
CodingEvents/CodingEvents.csproj | 13 ++++
.../Controllers/EventCategoryController.cs | 32 ++++++++++
CodingEvents/Controllers/EventsController.cs | 21 +++++--
CodingEvents/Data/EventData.cs | 35 -----------
CodingEvents/Data/EventDbContext.cs | 18 ++++++
...0230308200850_InitialMigration.Designer.cs | 46 ++++++++++++++
.../20230308200850_InitialMigration.cs | 44 +++++++++++++
...08201656_ContextAddedMigration.Designer.cs | 46 ++++++++++++++
.../20230308201656_ContextAddedMigration.cs | 22 +++++++
...02707_EventCategoryDbMigration.Designer.cs | 60 ++++++++++++++++++
...20230308202707_EventCategoryDbMigration.cs | 37 +++++++++++
...204054_EnumsCodeAddedMigration.Designer.cs | 63 +++++++++++++++++++
.../20230308204054_EnumsCodeAddedMigration.cs | 29 +++++++++
.../Migrations/EventDbContextModelSnapshot.cs | 60 ++++++++++++++++++
CodingEvents/Models/Event.cs | 6 +-
CodingEvents/Models/EventCategory.cs | 20 ++++++
CodingEvents/Models/EventType.cs | 12 ++++
CodingEvents/Program.cs | 11 +++-
CodingEvents/ViewModels/AddEventViewModel.cs | 14 ++++-
CodingEvents/Views/EventCategory/Index.cshtml | 15 +++++
CodingEvents/Views/Events/Add.cshtml | 10 ++-
CodingEvents/Views/Events/Index.cshtml | 4 ++
22 files changed, 568 insertions(+), 50 deletions(-)
create mode 100644 CodingEvents/Controllers/EventCategoryController.cs
delete mode 100644 CodingEvents/Data/EventData.cs
create mode 100644 CodingEvents/Data/EventDbContext.cs
create mode 100644 CodingEvents/Migrations/20230308200850_InitialMigration.Designer.cs
create mode 100644 CodingEvents/Migrations/20230308200850_InitialMigration.cs
create mode 100644 CodingEvents/Migrations/20230308201656_ContextAddedMigration.Designer.cs
create mode 100644 CodingEvents/Migrations/20230308201656_ContextAddedMigration.cs
create mode 100644 CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.Designer.cs
create mode 100644 CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.cs
create mode 100644 CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.Designer.cs
create mode 100644 CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.cs
create mode 100644 CodingEvents/Migrations/EventDbContextModelSnapshot.cs
create mode 100644 CodingEvents/Models/EventCategory.cs
create mode 100644 CodingEvents/Models/EventType.cs
create mode 100644 CodingEvents/Views/EventCategory/Index.cshtml
diff --git a/CodingEvents/CodingEvents.csproj b/CodingEvents/CodingEvents.csproj
index 8b352bf..6c57bdb 100644
--- a/CodingEvents/CodingEvents.csproj
+++ b/CodingEvents/CodingEvents.csproj
@@ -13,10 +13,23 @@
+
+
+
+
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
diff --git a/CodingEvents/Controllers/EventCategoryController.cs b/CodingEvents/Controllers/EventCategoryController.cs
new file mode 100644
index 0000000..72731c0
--- /dev/null
+++ b/CodingEvents/Controllers/EventCategoryController.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using CodingEvents.Data;
+using CodingEvents.Models;
+using Microsoft.AspNetCore.Mvc;
+
+// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace CodingEvents.Controllers
+{
+ public class EventCategoryController : Controller
+ {
+ private EventDbContext context;
+
+ public EventCategoryController(EventDbContext dbContext)
+ {
+ context = dbContext;
+ }
+
+ // GET: //
+ [HttpGet]
+ public IActionResult Index()
+ {
+ //ViewBag.title = "All Categories";
+ List categories = context.Categories.ToList();
+ return View(categories);
+ }
+ }
+}
+
diff --git a/CodingEvents/Controllers/EventsController.cs b/CodingEvents/Controllers/EventsController.cs
index 49ec466..865e0ae 100644
--- a/CodingEvents/Controllers/EventsController.cs
+++ b/CodingEvents/Controllers/EventsController.cs
@@ -13,10 +13,16 @@ namespace CodingEvents.Controllers
{
public class EventsController : Controller
{
+ private EventDbContext context;
+
+ public EventsController(EventDbContext dbContext)
+ {
+ context = dbContext;
+ }
// GET: //
public IActionResult Index()
{
- List events = new List(EventData.GetAll());
+ List events = context.Events.ToList();
return View(events);
}
@@ -38,10 +44,12 @@ public IActionResult Add(AddEventViewModel addEventViewModel)
{
Name = addEventViewModel.Name,
Description = addEventViewModel.Description,
- ContactEmail = addEventViewModel.ContactEmail
+ ContactEmail = addEventViewModel.ContactEmail,
+ Type = addEventViewModel.Type
};
- EventData.Add(newEvent);
+ context.Events.Add(newEvent);
+ context.SaveChanges();
return Redirect("/Events");
}
@@ -51,7 +59,7 @@ public IActionResult Add(AddEventViewModel addEventViewModel)
public IActionResult Delete()
{
- ViewBag.events = EventData.GetAll();
+ ViewBag.events = context.Events.ToList();
return View();
}
@@ -61,9 +69,12 @@ public IActionResult Delete(int[] eventIds)
{
foreach (int eventId in eventIds)
{
- EventData.Remove(eventId);
+ Event? theEvent = context.Events.Find(eventId);
+ context.Events.Remove(theEvent);
}
+ context.SaveChanges();
+
return Redirect("/Events");
}
}
diff --git a/CodingEvents/Data/EventData.cs b/CodingEvents/Data/EventData.cs
deleted file mode 100644
index e0662a6..0000000
--- a/CodingEvents/Data/EventData.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System;
-using CodingEvents.Models;
-
-namespace CodingEvents.Data
-{
- public class EventData
- {
- static private Dictionary Events = new Dictionary();
-
- // Fetch all the events
- public static IEnumerable GetAll()
- {
- return Events.Values;
- }
-
- // Add a new event to my dictionary
- public static void Add(Event newEvent)
- {
- Events.Add(newEvent.Id, newEvent);
- }
-
- // Remove an event from my dictionary
- public static void Remove(int id)
- {
- Events.Remove(id);
- }
-
- // Fetch a specific event
- public static Event GetById(int id)
- {
- return Events[id];
- }
- }
-}
-
diff --git a/CodingEvents/Data/EventDbContext.cs b/CodingEvents/Data/EventDbContext.cs
new file mode 100644
index 0000000..a5323d3
--- /dev/null
+++ b/CodingEvents/Data/EventDbContext.cs
@@ -0,0 +1,18 @@
+using System;
+using CodingEvents.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace CodingEvents.Data
+{
+ public class EventDbContext : DbContext
+ {
+ public DbSet Events { get; set; }
+ public DbSet Categories { get; set; }
+
+
+ public EventDbContext(DbContextOptions options) : base(options)
+ {
+ }
+ }
+}
+
diff --git a/CodingEvents/Migrations/20230308200850_InitialMigration.Designer.cs b/CodingEvents/Migrations/20230308200850_InitialMigration.Designer.cs
new file mode 100644
index 0000000..65fe7d5
--- /dev/null
+++ b/CodingEvents/Migrations/20230308200850_InitialMigration.Designer.cs
@@ -0,0 +1,46 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230308200850_InitialMigration")]
+ partial class InitialMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308200850_InitialMigration.cs b/CodingEvents/Migrations/20230308200850_InitialMigration.cs
new file mode 100644
index 0000000..254227c
--- /dev/null
+++ b/CodingEvents/Migrations/20230308200850_InitialMigration.cs
@@ -0,0 +1,44 @@
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class InitialMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterDatabase()
+ .Annotation("MySql:CharSet", "utf8mb4");
+
+ migrationBuilder.CreateTable(
+ name: "Events",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(type: "longtext", nullable: true)
+ .Annotation("MySql:CharSet", "utf8mb4"),
+ Description = table.Column(type: "longtext", nullable: true)
+ .Annotation("MySql:CharSet", "utf8mb4"),
+ ContactEmail = table.Column(type: "longtext", nullable: true)
+ .Annotation("MySql:CharSet", "utf8mb4")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Events", x => x.Id);
+ })
+ .Annotation("MySql:CharSet", "utf8mb4");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Events");
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308201656_ContextAddedMigration.Designer.cs b/CodingEvents/Migrations/20230308201656_ContextAddedMigration.Designer.cs
new file mode 100644
index 0000000..7e602e4
--- /dev/null
+++ b/CodingEvents/Migrations/20230308201656_ContextAddedMigration.Designer.cs
@@ -0,0 +1,46 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230308201656_ContextAddedMigration")]
+ partial class ContextAddedMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308201656_ContextAddedMigration.cs b/CodingEvents/Migrations/20230308201656_ContextAddedMigration.cs
new file mode 100644
index 0000000..1db35fd
--- /dev/null
+++ b/CodingEvents/Migrations/20230308201656_ContextAddedMigration.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class ContextAddedMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.Designer.cs b/CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.Designer.cs
new file mode 100644
index 0000000..7dea4cb
--- /dev/null
+++ b/CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.Designer.cs
@@ -0,0 +1,60 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230308202707_EventCategoryDbMigration")]
+ partial class EventCategoryDbMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.cs b/CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.cs
new file mode 100644
index 0000000..04d7f14
--- /dev/null
+++ b/CodingEvents/Migrations/20230308202707_EventCategoryDbMigration.cs
@@ -0,0 +1,37 @@
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class EventCategoryDbMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Categories",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(type: "longtext", nullable: true)
+ .Annotation("MySql:CharSet", "utf8mb4")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Categories", x => x.Id);
+ })
+ .Annotation("MySql:CharSet", "utf8mb4");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Categories");
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.Designer.cs b/CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.Designer.cs
new file mode 100644
index 0000000..84b256b
--- /dev/null
+++ b/CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.Designer.cs
@@ -0,0 +1,63 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230308204054_EnumsCodeAddedMigration")]
+ partial class EnumsCodeAddedMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.Property("Type")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.cs b/CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.cs
new file mode 100644
index 0000000..5d748c5
--- /dev/null
+++ b/CodingEvents/Migrations/20230308204054_EnumsCodeAddedMigration.cs
@@ -0,0 +1,29 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class EnumsCodeAddedMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "Type",
+ table: "Events",
+ type: "int",
+ nullable: false,
+ defaultValue: 0);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "Type",
+ table: "Events");
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/EventDbContextModelSnapshot.cs b/CodingEvents/Migrations/EventDbContextModelSnapshot.cs
new file mode 100644
index 0000000..ec479bd
--- /dev/null
+++ b/CodingEvents/Migrations/EventDbContextModelSnapshot.cs
@@ -0,0 +1,60 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ partial class EventDbContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.Property("Type")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Models/Event.cs b/CodingEvents/Models/Event.cs
index 6772b18..e42ccab 100644
--- a/CodingEvents/Models/Event.cs
+++ b/CodingEvents/Models/Event.cs
@@ -6,14 +6,12 @@ public class Event
public string? Name { get; set; }
public string? Description { get; set; }
public string? ContactEmail { get; set; }
+ public EventType Type { get; set; }
public int Id { get; set; }
- static private int nextId = 1;
public Event()
{
- Id = nextId;
- nextId++;
}
public Event(string name, string description, string contactEmail)
@@ -21,8 +19,6 @@ public Event(string name, string description, string contactEmail)
Name = name;
Description = description;
ContactEmail = contactEmail;
- Id = nextId;
- nextId++;
}
public override string? ToString()
diff --git a/CodingEvents/Models/EventCategory.cs b/CodingEvents/Models/EventCategory.cs
new file mode 100644
index 0000000..d3a294a
--- /dev/null
+++ b/CodingEvents/Models/EventCategory.cs
@@ -0,0 +1,20 @@
+using System;
+namespace CodingEvents.Models
+{
+ public class EventCategory
+ {
+ public int Id { get; set; }
+ public string? Name { get; set; }
+
+
+ public EventCategory()
+ {
+ }
+
+ public EventCategory(string name)
+ {
+ Name = name;
+ }
+ }
+}
+
diff --git a/CodingEvents/Models/EventType.cs b/CodingEvents/Models/EventType.cs
new file mode 100644
index 0000000..fa25a82
--- /dev/null
+++ b/CodingEvents/Models/EventType.cs
@@ -0,0 +1,12 @@
+using System;
+namespace CodingEvents.Models
+{
+ public enum EventType
+ {
+ Conference,
+ Meetup,
+ Workshop,
+ Social
+ }
+}
+
diff --git a/CodingEvents/Program.cs b/CodingEvents/Program.cs
index 9fbb57d..2aa7935 100644
--- a/CodingEvents/Program.cs
+++ b/CodingEvents/Program.cs
@@ -1,8 +1,17 @@
-var builder = WebApplication.CreateBuilder(args);
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+
+var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
+var connectionString = "server=localhost;user=codingevents;password=codingevents;database=coding-events";
+var serverVersion = new MySqlServerVersion(new Version(8, 0, 29));
+
+builder.Services.AddDbContext(dbContextOptions => dbContextOptions.UseMySql(connectionString, serverVersion));
+
+
var app = builder.Build();
// Configure the HTTP request pipeline.
diff --git a/CodingEvents/ViewModels/AddEventViewModel.cs b/CodingEvents/ViewModels/AddEventViewModel.cs
index 5e657bb..68ee651 100644
--- a/CodingEvents/ViewModels/AddEventViewModel.cs
+++ b/CodingEvents/ViewModels/AddEventViewModel.cs
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
+using CodingEvents.Models;
+using Microsoft.AspNetCore.Mvc.Rendering;
namespace CodingEvents.ViewModels
{
@@ -15,5 +17,15 @@ public class AddEventViewModel
[EmailAddress]
public string? ContactEmail { get; set; }
- }
+
+ public EventType Type { get; set; }
+
+ public List EventTypes { get; set; } = new List
+ {
+ new SelectListItem(EventType.Conference.ToString(), ((int)EventType.Conference).ToString()),
+ new SelectListItem(EventType.Meetup.ToString(), ((int)EventType.Meetup).ToString()),
+ new SelectListItem(EventType.Social.ToString(), ((int)EventType.Social).ToString()),
+ new SelectListItem(EventType.Workshop.ToString(), ((int)EventType.Workshop).ToString())
+ };
+ }
}
diff --git a/CodingEvents/Views/EventCategory/Index.cshtml b/CodingEvents/Views/EventCategory/Index.cshtml
new file mode 100644
index 0000000..175f59b
--- /dev/null
+++ b/CodingEvents/Views/EventCategory/Index.cshtml
@@ -0,0 +1,15 @@
+@model List
+
+All Event Categories
+
+
+
+ Category Name
+
+ @foreach (EventCategory category in Model)
+ {
+
+ @category.Name
+
+ }
+
diff --git a/CodingEvents/Views/Events/Add.cshtml b/CodingEvents/Views/Events/Add.cshtml
index 3b6b7eb..8fb89be 100644
--- a/CodingEvents/Views/Events/Add.cshtml
+++ b/CodingEvents/Views/Events/Add.cshtml
@@ -6,18 +6,22 @@
\ No newline at end of file
diff --git a/CodingEvents/Views/Events/Index.cshtml b/CodingEvents/Views/Events/Index.cshtml
index 5f61f68..9bbcff6 100644
--- a/CodingEvents/Views/Events/Index.cshtml
+++ b/CodingEvents/Views/Events/Index.cshtml
@@ -31,6 +31,9 @@ else
Contact Email
+
+ Event Type
+
@foreach (var evt in Model)
{
@@ -39,6 +42,7 @@ else
@evt.Name
@evt.Description
@evt.ContactEmail
+ @evt.Type
}
From 8e8ae9bdf260f1e08d89d0a41f795e52de09b9f2 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 8 Mar 2023 14:50:34 -0600
Subject: [PATCH 09/11] connectionString updated
---
CodingEvents/Program.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CodingEvents/Program.cs b/CodingEvents/Program.cs
index 2aa7935..ec1ea32 100644
--- a/CodingEvents/Program.cs
+++ b/CodingEvents/Program.cs
@@ -6,7 +6,7 @@
// Add services to the container.
builder.Services.AddControllersWithViews();
-var connectionString = "server=localhost;user=codingevents;password=codingevents;database=coding-events";
+var connectionString = "server=localhost;user=coding_events;password=coding_events;database=coding_events";
var serverVersion = new MySqlServerVersion(new Version(8, 0, 29));
builder.Services.AddDbContext(dbContextOptions => dbContextOptions.UseMySql(connectionString, serverVersion));
From b64e792789990a25d8ce67fa8a6e3832c99d5295 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 8 Mar 2023 15:35:18 -0600
Subject: [PATCH 10/11] studio added
---
.../Controllers/EventCategoryController.cs | 30 ++++++++-
...01_EventCategoryAddedMigration.Designer.cs | 63 +++++++++++++++++++
...30308211501_EventCategoryAddedMigration.cs | 22 +++++++
...4_EventCategoryUpdateMigration.Designer.cs | 63 +++++++++++++++++++
...0308213444_EventCategoryUpdateMigration.cs | 22 +++++++
CodingEvents/Program.cs | 2 +-
.../ViewModels/AddEventCategoryViewModel.cs | 13 ++++
.../Views/EventCategory/Create.cshtml | 12 ++++
CodingEvents/Views/EventCategory/Index.cshtml | 27 +++++---
CodingEvents/Views/Shared/_Layout.cshtml | 13 +++-
10 files changed, 255 insertions(+), 12 deletions(-)
create mode 100644 CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.Designer.cs
create mode 100644 CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.cs
create mode 100644 CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.Designer.cs
create mode 100644 CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.cs
create mode 100644 CodingEvents/ViewModels/AddEventCategoryViewModel.cs
create mode 100644 CodingEvents/Views/EventCategory/Create.cshtml
diff --git a/CodingEvents/Controllers/EventCategoryController.cs b/CodingEvents/Controllers/EventCategoryController.cs
index 72731c0..cff66f9 100644
--- a/CodingEvents/Controllers/EventCategoryController.cs
+++ b/CodingEvents/Controllers/EventCategoryController.cs
@@ -4,6 +4,7 @@
using System.Threading.Tasks;
using CodingEvents.Data;
using CodingEvents.Models;
+using CodingEvents.ViewModels;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -23,10 +24,37 @@ public EventCategoryController(EventDbContext dbContext)
[HttpGet]
public IActionResult Index()
{
- //ViewBag.title = "All Categories";
List categories = context.Categories.ToList();
+
return View(categories);
}
+
+ [HttpGet]
+ [Route("EventCategory/Create")]
+ public IActionResult Create()
+ {
+ AddEventCategoryViewModel addEventCategoryViewModel = new AddEventCategoryViewModel();
+
+ return View(addEventCategoryViewModel);
+ }
+
+ [HttpPost]
+ public IActionResult ProcessCreateEventCategoryForm(AddEventCategoryViewModel addEventCategoryViewModel)
+ {
+ if (ModelState.IsValid)
+ {
+ EventCategory theCategory = new EventCategory
+ {
+ Name = addEventCategoryViewModel.Name
+ };
+
+ context.Categories.Add(theCategory);
+ context.SaveChanges();
+
+ return Redirect("/EventCategory");
+ }
+ return View("Create", addEventCategoryViewModel);
+ }
}
}
diff --git a/CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.Designer.cs b/CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.Designer.cs
new file mode 100644
index 0000000..6bdd46c
--- /dev/null
+++ b/CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.Designer.cs
@@ -0,0 +1,63 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230308211501_EventCategoryAddedMigration")]
+ partial class EventCategoryAddedMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.Property("Type")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.cs b/CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.cs
new file mode 100644
index 0000000..93dcc62
--- /dev/null
+++ b/CodingEvents/Migrations/20230308211501_EventCategoryAddedMigration.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class EventCategoryAddedMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.Designer.cs b/CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.Designer.cs
new file mode 100644
index 0000000..eaefb39
--- /dev/null
+++ b/CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.Designer.cs
@@ -0,0 +1,63 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230308213444_EventCategoryUpdateMigration")]
+ partial class EventCategoryUpdateMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.Property("Type")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.cs b/CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.cs
new file mode 100644
index 0000000..f3aa4a7
--- /dev/null
+++ b/CodingEvents/Migrations/20230308213444_EventCategoryUpdateMigration.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class EventCategoryUpdateMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/CodingEvents/Program.cs b/CodingEvents/Program.cs
index ec1ea32..2aa7935 100644
--- a/CodingEvents/Program.cs
+++ b/CodingEvents/Program.cs
@@ -6,7 +6,7 @@
// Add services to the container.
builder.Services.AddControllersWithViews();
-var connectionString = "server=localhost;user=coding_events;password=coding_events;database=coding_events";
+var connectionString = "server=localhost;user=codingevents;password=codingevents;database=coding-events";
var serverVersion = new MySqlServerVersion(new Version(8, 0, 29));
builder.Services.AddDbContext(dbContextOptions => dbContextOptions.UseMySql(connectionString, serverVersion));
diff --git a/CodingEvents/ViewModels/AddEventCategoryViewModel.cs b/CodingEvents/ViewModels/AddEventCategoryViewModel.cs
new file mode 100644
index 0000000..2fb4d82
--- /dev/null
+++ b/CodingEvents/ViewModels/AddEventCategoryViewModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace CodingEvents.ViewModels
+{
+ public class AddEventCategoryViewModel
+ {
+ [Required(ErrorMessage ="Please add a category type")]
+ [StringLength(20, MinimumLength =1, ErrorMessage ="Category type should be between 1-20 characters")]
+ public string? Name { get; set; }
+ }
+}
+
diff --git a/CodingEvents/Views/EventCategory/Create.cshtml b/CodingEvents/Views/EventCategory/Create.cshtml
new file mode 100644
index 0000000..0ae0aa3
--- /dev/null
+++ b/CodingEvents/Views/EventCategory/Create.cshtml
@@ -0,0 +1,12 @@
+@model CodingEvents.ViewModels.AddEventCategoryViewModel
+
+Add New Category
+
+
\ No newline at end of file
diff --git a/CodingEvents/Views/EventCategory/Index.cshtml b/CodingEvents/Views/EventCategory/Index.cshtml
index 175f59b..41af2f8 100644
--- a/CodingEvents/Views/EventCategory/Index.cshtml
+++ b/CodingEvents/Views/EventCategory/Index.cshtml
@@ -2,14 +2,23 @@
All Event Categories
-
-
- Category Name
-
- @foreach (EventCategory category in Model)
- {
+@if (Model.Count == 0)
+{
+ No Event Categories yet!
+}
+else
+{
+
- @category.Name
+ Id
+ Category Name
- }
-
+ @foreach (EventCategory category in Model)
+ {
+
+ @category.Id
+ @category.Name
+
+ }
+
+}
\ No newline at end of file
diff --git a/CodingEvents/Views/Shared/_Layout.cshtml b/CodingEvents/Views/Shared/_Layout.cshtml
index 9d9d7b1..9480a7f 100644
--- a/CodingEvents/Views/Shared/_Layout.cshtml
+++ b/CodingEvents/Views/Shared/_Layout.cshtml
@@ -19,7 +19,18 @@
From 5981376e682425d6d57c78e1619d46a4dcbdf687 Mon Sep 17 00:00:00 2001
From: Courtney Frey
Date: Wed, 15 Mar 2023 14:17:35 -0500
Subject: [PATCH 11/11] testing
---
...5185642_InitialMigration-NewDB.Designer.cs | 63 +++++++++++++++++++
.../20230315185642_InitialMigration-NewDB.cs | 22 +++++++
.../20230315190856_DBCheck.Designer.cs | 63 +++++++++++++++++++
.../Migrations/20230315190856_DBCheck.cs | 22 +++++++
CodingEvents/Program.cs | 5 +-
5 files changed, 172 insertions(+), 3 deletions(-)
create mode 100644 CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.Designer.cs
create mode 100644 CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.cs
create mode 100644 CodingEvents/Migrations/20230315190856_DBCheck.Designer.cs
create mode 100644 CodingEvents/Migrations/20230315190856_DBCheck.cs
diff --git a/CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.Designer.cs b/CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.Designer.cs
new file mode 100644
index 0000000..410a877
--- /dev/null
+++ b/CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.Designer.cs
@@ -0,0 +1,63 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230315185642_InitialMigration-NewDB")]
+ partial class InitialMigrationNewDB
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.Property("Type")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.cs b/CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.cs
new file mode 100644
index 0000000..49d6c47
--- /dev/null
+++ b/CodingEvents/Migrations/20230315185642_InitialMigration-NewDB.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class InitialMigrationNewDB : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230315190856_DBCheck.Designer.cs b/CodingEvents/Migrations/20230315190856_DBCheck.Designer.cs
new file mode 100644
index 0000000..ebbe326
--- /dev/null
+++ b/CodingEvents/Migrations/20230315190856_DBCheck.Designer.cs
@@ -0,0 +1,63 @@
+//
+using CodingEvents.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ [DbContext(typeof(EventDbContext))]
+ [Migration("20230315190856_DBCheck")]
+ partial class DBCheck
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("CodingEvents.Models.Event", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("ContactEmail")
+ .HasColumnType("longtext");
+
+ b.Property("Description")
+ .HasColumnType("longtext");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.Property("Type")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Events");
+ });
+
+ modelBuilder.Entity("CodingEvents.Models.EventCategory", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ b.Property("Name")
+ .HasColumnType("longtext");
+
+ b.HasKey("Id");
+
+ b.ToTable("Categories");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/CodingEvents/Migrations/20230315190856_DBCheck.cs b/CodingEvents/Migrations/20230315190856_DBCheck.cs
new file mode 100644
index 0000000..ae767c7
--- /dev/null
+++ b/CodingEvents/Migrations/20230315190856_DBCheck.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace CodingEvents.Migrations
+{
+ ///
+ public partial class DBCheck : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/CodingEvents/Program.cs b/CodingEvents/Program.cs
index 2aa7935..9425427 100644
--- a/CodingEvents/Program.cs
+++ b/CodingEvents/Program.cs
@@ -6,12 +6,11 @@
// Add services to the container.
builder.Services.AddControllersWithViews();
-var connectionString = "server=localhost;user=codingevents;password=codingevents;database=coding-events";
-var serverVersion = new MySqlServerVersion(new Version(8, 0, 29));
+var connectionString = "server=localhost;user=test-user;password=test-user;database=coding-events";
+var serverVersion = new MySqlServerVersion(new Version(8, 0,29));
builder.Services.AddDbContext(dbContextOptions => dbContextOptions.UseMySql(connectionString, serverVersion));
-
var app = builder.Build();
// Configure the HTTP request pipeline.