This repository was archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathEventCategoryController.cs
More file actions
57 lines (48 loc) · 1.6 KB
/
EventCategoryController.cs
File metadata and controls
57 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CodingEventsDemo.Data;
using CodingEventsDemo.Models;
using Microsoft.AspNetCore.Mvc;
using CodingEventsDemo.ViewModels;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace CodingEventsDemo.Controllers
{
public class EventCategoryController : Controller
{
private EventDbContext context;
public EventCategoryController(EventDbContext dbContext)
{
context = dbContext;
}
// GET: /<controller>/
[HttpGet]
public IActionResult Index()
{
List<EventCategory> categories = context.Categories.ToList();
return View(categories);
}
[HttpGet]
public IActionResult Create()
{
AddEventCategoryViewModel addEventCategoryViewModel = new AddEventCategoryViewModel();
return View(addEventCategoryViewModel);
}
[HttpPost]
public IActionResult ProcessCreateEventCategoryForm(AddEventCategoryViewModel addEventCategoryViewModel)
{
if (ModelState.IsValid)
{
EventCategory newCategory = new EventCategory
{
Name = addEventCategoryViewModel.Name
};
context.Categories.Add(newCategory);
context.SaveChanges();
return Redirect("/EventCategory");
}
return View("Create", addEventCategoryViewModel);
}
}
}