mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using WebApp.Data;
|
|
using WebApp.Entities;
|
|
|
|
namespace WebApp.Controllers
|
|
{
|
|
public class EventsController : Controller
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public EventsController(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Create(Event ev)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
ev.EventDate = DateTime.SpecifyKind(ev.EventDate, DateTimeKind.Utc);
|
|
_context.Events.Add(ev);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return RedirectToAction("Index", "Home");
|
|
}
|
|
return View(ev);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Delete(int id)
|
|
{
|
|
var ev = await _context.Events.FindAsync(id);
|
|
if (ev != null)
|
|
{
|
|
_context.Events.Remove(ev);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
return RedirectToAction("Index", "Home");
|
|
}
|
|
|
|
}
|
|
}
|