mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
Dodawanie/Usuwanie
Dodawanie/Usuwanie (nie chce tu przeklinać)
This commit is contained in:
50
WebApp/Controllers/EventsController.cs
Normal file
50
WebApp/Controllers/EventsController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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.Date = DateTime.SpecifyKind(ev.Date, 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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using WebApp.Data;
|
||||
using WebApp.Models;
|
||||
|
||||
namespace WebApp.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public class HomeController : Controller
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, ApplicationDbContext context)
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
var events = _context.Events.ToList(); // pobieranie danych z bazy
|
||||
return View(events); // przekazanie do widoku
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user