Delete, Edit Announcement, style fixes
This commit is contained in:
@@ -7,13 +7,17 @@
|
||||
Announcement announcement = (Announcement)ViewData["announcement"];
|
||||
ViewData["Title"] = $"{announcement.Title}";
|
||||
}
|
||||
<h1>@announcement.Title</h1>
|
||||
<h1 @if (announcement.IsImportant)
|
||||
{
|
||||
@: style="color: red;"
|
||||
}>@announcement.Title
|
||||
</h1>
|
||||
<p>
|
||||
Published @announcement.PublishDate.ToString("g") by @announcement.Author.Name
|
||||
@Html.Raw((announcement.Author.Role == UserRole.ADMIN || announcement.Author.Role == UserRole.MANAGER)
|
||||
? $"<b>({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(announcement.Author.Role.ToString().ToLower())})</b>"
|
||||
: "")
|
||||
@(announcement.IsImportant ? "Important" : "") @(announcement.IsSticky ? "Sticky" : "")
|
||||
@(announcement.IsSticky ? "Pinned" : "")
|
||||
</p>
|
||||
<p>
|
||||
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN" || User.Identity.Name == announcement.Author.Name)
|
||||
|
@@ -15,9 +15,12 @@
|
||||
{
|
||||
<div class="card" style="display:inline-flex; width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@announcement.Title</h5>
|
||||
<h5 class="card-title" @if (announcement.IsImportant)
|
||||
{
|
||||
@: style="color: red;"
|
||||
}>@announcement.Title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">@announcement.Author.Name</h6>
|
||||
<p class="card-text">@announcement.Description.PadRight(100).Trim()</p>
|
||||
<p class="card-text">@announcement.Description.PadRight(100).Substring(0,100).Trim()</p>
|
||||
<a href="./Announcement?id=@announcement.ID" class="btn btn-primary">More details</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -13,13 +13,13 @@ namespace WebApp.Pages
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public void OnPost()
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||
UserManager userManager = new UserManager();
|
||||
User user = userManager.GetUserById(int.Parse(User.FindFirstValue("id")));
|
||||
announcementManager.CreateAnnouncement(Announcement.Title, Announcement.Description, user, DateTime.Now, Announcement.IsImportant, Announcement.IsSticky);
|
||||
RedirectToPage("Announcements");
|
||||
return RedirectToPage("Announcements");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
31
StudentHouseDashboard/WebApp/Pages/DeleteAnnouncement.cshtml
Normal file
31
StudentHouseDashboard/WebApp/Pages/DeleteAnnouncement.cshtml
Normal file
@@ -0,0 +1,31 @@
|
||||
@page
|
||||
@using Models;
|
||||
@model WebApp.Pages.DeleteAnnouncementModel
|
||||
@{
|
||||
ViewData["Title"] = "Delete announcement";
|
||||
Announcement announcement = (Announcement)ViewData["announcement"];
|
||||
}
|
||||
|
||||
@if (announcement == null)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
Unable to find announcement! Do you have permission?
|
||||
</div>
|
||||
<a type="button" class="btn btn-primary" asp-page="Announcements">Return to all announcements</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post">
|
||||
<h1>Are you sure you want to delete this announcement?</h1>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@announcement.Title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-body-secondary">@announcement.Author.Name - @announcement.PublishDate</h6>
|
||||
<p class="card-text">@Html.Raw(announcement.Description.Replace(Environment.NewLine, "<br />"))</p>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" asp-for="AnnouncementId" value="@announcement.ID" />
|
||||
<input type="submit" value="Yes" class="btn btn-danger" />
|
||||
<a type="button" class="btn btn-secondary" asp-page="Announcements">No</a>
|
||||
</form>
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using Logic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class DeleteAnnouncementModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public int AnnouncementId { get; set; }
|
||||
public void OnGet(int id)
|
||||
{
|
||||
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||
if (id != null)
|
||||
{
|
||||
Announcement announcement = announcementManager.GetAnnouncementById(id);
|
||||
if (announcement.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN"))
|
||||
{
|
||||
ViewData["announcement"] = announcement;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||
announcementManager.DeleteAnnouncement(AnnouncementId);
|
||||
return RedirectToPage("Announcements");
|
||||
}
|
||||
}
|
||||
}
|
43
StudentHouseDashboard/WebApp/Pages/EditAnnouncement.cshtml
Normal file
43
StudentHouseDashboard/WebApp/Pages/EditAnnouncement.cshtml
Normal file
@@ -0,0 +1,43 @@
|
||||
@page
|
||||
@using Models;
|
||||
@model WebApp.Pages.EditAnnouncementModel
|
||||
@{
|
||||
ViewData["Title"] = "Edit announcement";
|
||||
Model.Announcement = (Announcement)ViewData["announcement"];
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (Model.Announcement == null)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
Unable to find announcement! Do you have permission?
|
||||
</div>
|
||||
<a type="button" class="btn btn-primary" asp-page="Announcements">Return to all announcements</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="Announcement.Title" class="form-label">Title: </label>
|
||||
<input asp-for="Announcement.Title" class="form-control" />
|
||||
</div>
|
||||
@if (HttpContext.User.IsInRole("ADMIN") || HttpContext.User.IsInRole("MANAGER"))
|
||||
{
|
||||
<div class="mb-3">
|
||||
<label asp-for="Announcement.IsImportant" class="form-label">Important: </label>
|
||||
@Html.CheckBoxFor(model => model.Announcement.IsImportant)
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Announcement.IsSticky" class="form-label">Pinned: </label>
|
||||
@Html.CheckBoxFor(model => model.Announcement.IsSticky)
|
||||
</div>
|
||||
}
|
||||
<div class="mb-3">
|
||||
<label asp-for="Announcement.Description" class="form-label">Description: </label>
|
||||
<textarea asp-for="Announcement.Description" class="form-control" rows="5"></textarea>
|
||||
</div>
|
||||
<input type="hidden" asp-for="Announcement.ID" />
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</form>
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using Logic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class EditAnnouncementModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public Announcement Announcement { get; set; }
|
||||
public void OnGet(int id)
|
||||
{
|
||||
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||
if (id != null)
|
||||
{
|
||||
Announcement announcement = announcementManager.GetAnnouncementById(id);
|
||||
if (announcement.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN") )
|
||||
{
|
||||
ViewData["announcement"] = announcement;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||
announcementManager.UpdateAnnouncement(Announcement.ID, Announcement.Title, Announcement.Description, Announcement.IsImportant, Announcement.IsSticky);
|
||||
return RedirectToPage("Announcements");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user