diff --git a/WebApp.sln b/WebApp.sln index 664d0b8..cbfcca6 100644 --- a/WebApp.sln +++ b/WebApp.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.13.35919.96 d17.13 +VisualStudioVersion = 17.13.35919.96 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp", "WebApp\WebApp.csproj", "{D6D76D22-3581-4984-B44E-D1C981976C0B}" EndProject diff --git a/WebApp/Controllers/EventsController.cs b/WebApp/Controllers/EventsController.cs new file mode 100644 index 0000000..fac7ce6 --- /dev/null +++ b/WebApp/Controllers/EventsController.cs @@ -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 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 Delete(int id) + { + var ev = await _context.Events.FindAsync(id); + if (ev != null) + { + _context.Events.Remove(ev); + await _context.SaveChangesAsync(); + } + return RedirectToAction("Index", "Home"); + } + + } +} diff --git a/WebApp/Controllers/HomeController.cs b/WebApp/Controllers/HomeController.cs index cc22d2a..2b5443c 100644 --- a/WebApp/Controllers/HomeController.cs +++ b/WebApp/Controllers/HomeController.cs @@ -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 _logger; + private readonly ApplicationDbContext _context; + + public HomeController(ILogger logger, ApplicationDbContext context) { - private readonly ILogger _logger; + _logger = logger; + _context = context; + } - public HomeController(ILogger 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 }); } } diff --git a/WebApp/Views/Events/Create.cshtml b/WebApp/Views/Events/Create.cshtml new file mode 100644 index 0000000..b5fef63 --- /dev/null +++ b/WebApp/Views/Events/Create.cshtml @@ -0,0 +1,36 @@ +@model WebApp.Entities.Event + +@{ + ViewData["Title"] = "Create Event"; +} + +

Create Event

+ +
+
+ + + +
+
+ + + +
+
+ + +
+
+ + + +
+ +
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } +} diff --git a/WebApp/Views/Events/Create.cshtml.cs b/WebApp/Views/Events/Create.cshtml.cs new file mode 100644 index 0000000..9a8d4fa --- /dev/null +++ b/WebApp/Views/Events/Create.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Views.Events +{ + public class CreateModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/WebApp/Views/Home/Index.cshtml b/WebApp/Views/Home/Index.cshtml index bcfd79a..f1e0bda 100644 --- a/WebApp/Views/Home/Index.cshtml +++ b/WebApp/Views/Home/Index.cshtml @@ -1,8 +1,49 @@ -@{ +@model List + +@{ ViewData["Title"] = "Home Page"; } + +
+ +

Lista wydarzeń

+ +@if (Model.Any()) +{ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
NazwaMiejsceDataAkcje
@item.Name@item.Place@item.Date.ToString("yyyy-MM-dd HH:mm") +
+ + +
+
+} +else +{ +

Brak wydarzeń do wyświetlenia.

+}