Events webapp
This commit is contained in:
@@ -134,8 +134,8 @@ namespace Data
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
cmd.Parameters.AddWithValue("@desc", description);
|
||||
cmd.Parameters.AddWithValue("@title", title);
|
||||
cmd.Parameters.AddWithValue("@status", startDate);
|
||||
cmd.Parameters.AddWithValue("@severity", endDate);
|
||||
cmd.Parameters.AddWithValue("@start", startDate);
|
||||
cmd.Parameters.AddWithValue("@end", endDate);
|
||||
var writer = cmd.ExecuteNonQuery();
|
||||
if (writer == -1)
|
||||
{
|
||||
|
31
StudentHouseDashboard/WebApp/Pages/DeleteEvent.cshtml
Normal file
31
StudentHouseDashboard/WebApp/Pages/DeleteEvent.cshtml
Normal file
@@ -0,0 +1,31 @@
|
||||
@page
|
||||
@using Models;
|
||||
@model WebApp.Pages.DeleteEventModel
|
||||
@{
|
||||
ViewData["Title"] = "Delete event";
|
||||
Event _event = (Event)ViewData["event"];
|
||||
}
|
||||
|
||||
@if (_event == null)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
Unable to find event! Do you have permission?
|
||||
</div>
|
||||
<a type="button" class="btn btn-primary" asp-page="events">Return to all events</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post">
|
||||
<h1>Are you sure you want to delete this event?</h1>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@_event.Title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">@_event.Author.Name - @_event.PublishDate</h6>
|
||||
<p class="card-text">@Html.Raw(_event.Description.Replace(Environment.NewLine, "<br />"))</p>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" asp-for="EventId" value="@_event.ID" />
|
||||
<input type="submit" value="Yes" class="btn btn-danger" />
|
||||
<a type="button" class="btn btn-secondary" asp-page="Events">No</a>
|
||||
</form>
|
||||
}
|
40
StudentHouseDashboard/WebApp/Pages/DeleteEvent.cshtml.cs
Normal file
40
StudentHouseDashboard/WebApp/Pages/DeleteEvent.cshtml.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Logic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
[Authorize]
|
||||
public class DeleteEventModel : PageModel
|
||||
{
|
||||
private readonly IEventRepository eventRepository;
|
||||
|
||||
public DeleteEventModel(IEventRepository eventRepository)
|
||||
{
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
[BindProperty]
|
||||
public int EventId { get; set; }
|
||||
public void OnGet(int id)
|
||||
{
|
||||
EventManager eventManager = new EventManager(eventRepository);
|
||||
if (id != null)
|
||||
{
|
||||
Event @event = eventManager.GetEventById(id);
|
||||
if (@event.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN"))
|
||||
{
|
||||
ViewData["event"] = @event;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
EventManager eventManager = new EventManager(eventRepository);
|
||||
eventManager.DeleteEvent(EventId);
|
||||
return RedirectToPage("Events");
|
||||
}
|
||||
}
|
||||
}
|
41
StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml
Normal file
41
StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml
Normal file
@@ -0,0 +1,41 @@
|
||||
@page
|
||||
@using Models;
|
||||
@model WebApp.Pages.EditEventModel
|
||||
@{
|
||||
ViewData["Title"] = "Edit event";
|
||||
Model.Event = (Event)ViewData["event"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@if (Model.Event == null)
|
||||
{
|
||||
<h1>Create new event</h1>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
}
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="Event.Title" class="form-label">Title: </label>
|
||||
<input asp-for="Event.Title" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Event.StartDate" class="form-label">Start date: </label>
|
||||
<input asp-for="Event.StartDate" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Event.EndDate" class="form-label">End date: </label>
|
||||
<input asp-for="Event.EndDate" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Event.Description" class="form-label">Description: </label>
|
||||
<textarea asp-for="Event.Description" class="form-control" rows="5"></textarea>
|
||||
</div>
|
||||
@if (ViewData["event"] == null)
|
||||
{
|
||||
<input type="hidden" name="n" value="true" />
|
||||
}
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</form>
|
53
StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml.cs
Normal file
53
StudentHouseDashboard/WebApp/Pages/EditEvent.cshtml.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Logic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
[Authorize]
|
||||
public class EditEventModel : PageModel
|
||||
{
|
||||
private readonly IEventRepository _eventRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public EditEventModel(IEventRepository eventRepository, IUserRepository userRepository)
|
||||
{
|
||||
_eventRepository = eventRepository;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
[BindProperty]
|
||||
public Event Event { get; set; }
|
||||
public void OnGet(int? id)
|
||||
{
|
||||
EventManager eventManager = new EventManager(_eventRepository);
|
||||
if (id != null)
|
||||
{
|
||||
Event @event = eventManager.GetEventById(id.Value);
|
||||
if (@event.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN") )
|
||||
{
|
||||
ViewData["event"] = @event;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IActionResult OnPost(bool? n)
|
||||
{
|
||||
if (n != null && n.Value)
|
||||
{
|
||||
UserManager userManager = new UserManager(_userRepository);
|
||||
User user = userManager.GetUserById(int.Parse(User.FindFirstValue("id")));
|
||||
EventManager eventManager = new EventManager(_eventRepository);
|
||||
eventManager.CreateEvent(Event.Title, Event.Description, user, DateTime.Now, Event.StartDate, Event.EndDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventManager eventManager = new EventManager(_eventRepository);
|
||||
eventManager.UpdateEvent(Event.ID, Event.Title, Event.Description, Event.StartDate, Event.EndDate);
|
||||
}
|
||||
|
||||
return RedirectToPage("Events");
|
||||
}
|
||||
}
|
||||
}
|
26
StudentHouseDashboard/WebApp/Pages/Event.cshtml
Normal file
26
StudentHouseDashboard/WebApp/Pages/Event.cshtml
Normal file
@@ -0,0 +1,26 @@
|
||||
@page
|
||||
@using Models;
|
||||
@using System.Globalization
|
||||
@using System.Security.Claims;
|
||||
@model WebApp.Pages.EventModel
|
||||
@{
|
||||
Event _event = (Event)ViewData["event"];
|
||||
ViewData["Title"] = $"{_event.Title}";
|
||||
}
|
||||
<h1>@_event.Title</h1>
|
||||
<h2>@_event.StartDate.ToString("g") - @_event.EndDate.ToString("g")</h2>
|
||||
<p>
|
||||
Published @_event.PublishDate.ToString("g") by @_event.Author.Name
|
||||
@Html.Raw((_event.Author.Role == UserRole.ADMIN || _event.Author.Role == UserRole.MANAGER)
|
||||
? $"<b>({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(_event.Author.Role.ToString().ToLower())})</b>"
|
||||
: "")
|
||||
</p>
|
||||
<p>
|
||||
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN" || User.Identity.Name == _event.Author.Name)
|
||||
{
|
||||
<a href="./EditEvent?id=@_event.ID" class="btn btn-outline-warning">Edit</a>
|
||||
<a href="./DeleteEvent?id=@_event.ID" class="btn btn-outline-danger">Delete</a>
|
||||
}
|
||||
</p>
|
||||
<hr/>
|
||||
<p>@Html.Raw(_event.Description.Replace(Environment.NewLine, "<br />"))</p>
|
25
StudentHouseDashboard/WebApp/Pages/Event.cshtml.cs
Normal file
25
StudentHouseDashboard/WebApp/Pages/Event.cshtml.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Logic;
|
||||
using Models;
|
||||
using Data;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
[Authorize]
|
||||
public class EventModel : PageModel
|
||||
{
|
||||
private readonly IEventRepository eventRepository;
|
||||
|
||||
public EventModel(IEventRepository eventRepository)
|
||||
{
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
public void OnGet(int id)
|
||||
{
|
||||
EventManager eventManager = new EventManager(eventRepository);
|
||||
ViewData.Add("event", eventManager.GetEventById(id));
|
||||
}
|
||||
}
|
||||
}
|
25
StudentHouseDashboard/WebApp/Pages/Events.cshtml
Normal file
25
StudentHouseDashboard/WebApp/Pages/Events.cshtml
Normal file
@@ -0,0 +1,25 @@
|
||||
@page
|
||||
@using Models;
|
||||
@using System.Security.Claims;
|
||||
@model WebApp.Pages.EventsModel
|
||||
@{
|
||||
ViewData["Title"] = "Events";
|
||||
List<Event> events = ((List<Event>)ViewData["events"]).ToList();
|
||||
}
|
||||
|
||||
<a href="./EditEvent" class="btn btn-primary">Create new event</a>
|
||||
|
||||
<div class="mb-3 mt-3">
|
||||
@foreach (Event _event in events)
|
||||
{
|
||||
<div class="card" style="display:inline-flex; width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@_event.Title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">@_event.StartDate.ToString("g") - @_event.EndDate.ToString("g")</h6>
|
||||
<h6 class="card-subtitle mb-2 text-muted">@_event.Author.Name</h6>
|
||||
<p class="card-text">@_event.Description.PadRight(100).Substring(0,100).Trim()</p>
|
||||
<a href="./Event?id=@_event.ID" class="btn btn-primary">More details</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
27
StudentHouseDashboard/WebApp/Pages/Events.cshtml.cs
Normal file
27
StudentHouseDashboard/WebApp/Pages/Events.cshtml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Logic;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
[Authorize]
|
||||
public class EventsModel : PageModel
|
||||
{
|
||||
private readonly IEventRepository _eventRepository;
|
||||
|
||||
public EventsModel(IEventRepository eventRepository)
|
||||
{
|
||||
_eventRepository = eventRepository;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
EventManager eventManager = new EventManager(_eventRepository);
|
||||
ViewData["events"] = eventManager.GetAllCurrentEvents();
|
||||
}
|
||||
}
|
||||
}
|
@@ -30,15 +30,14 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Complaints">Complaints</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Events">Events</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
@if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark">Logged in as @User.Identity.Name</a>
|
||||
</li>
|
||||
@if (User.IsInRole("ADMIN") || User.IsInRole("MANAGER"))
|
||||
{
|
||||
<li class="nav-item">
|
||||
@@ -46,7 +45,7 @@
|
||||
</li>
|
||||
}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/ChangePassword">Change password</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/ChangePassword"><b>@User.Identity.Name</b></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Logout">Logout</a>
|
||||
@@ -74,7 +73,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
<p>StudentHouseDashboard © 2023 <a asp-area="" asp-page="/Privacy">Privacy</a> <a asp-area="" asp-page="/Contact">Contact</a></p>
|
||||
<p>StudentHouseDashboard © 2023 <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
@@ -7,6 +7,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="Pages\Events.cshtml">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Update="Pages\Index.cshtml">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
|
Reference in New Issue
Block a user