CreateAnnouncement, pinned announcements before regular
This commit is contained in:
@@ -13,6 +13,10 @@ namespace Models
|
||||
IsSticky = isSticky;
|
||||
}
|
||||
|
||||
public Announcement()
|
||||
{
|
||||
|
||||
}
|
||||
public List<Comment> Comments
|
||||
{
|
||||
get;set;
|
||||
|
@@ -20,7 +20,10 @@ namespace Models
|
||||
Title = title;
|
||||
PublishDate = publishDate;
|
||||
}
|
||||
|
||||
protected GenericMessage()
|
||||
{
|
||||
|
||||
}
|
||||
public int ID
|
||||
{
|
||||
get; private set;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
@page
|
||||
@using Models;
|
||||
@using System.Globalization
|
||||
@using System.Security.Claims;
|
||||
@model WebApp.Pages.AnnouncementModel
|
||||
@{
|
||||
Announcement announcement = (Announcement)ViewData["announcement"];
|
||||
@@ -14,6 +15,13 @@
|
||||
: "")
|
||||
@(announcement.IsImportant ? "Important" : "") @(announcement.IsSticky ? "Sticky" : "")
|
||||
</p>
|
||||
<p>
|
||||
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN" || User.Identity.Name == announcement.Author.Name)
|
||||
{
|
||||
<a href="./EditAnnouncement?id=@announcement.ID" class="btn btn-outline-warning">Edit</a>
|
||||
<a href="./DeleteAnnouncement?id=@announcement.ID" class="btn btn-outline-danger">Delete</a>
|
||||
}
|
||||
</p>
|
||||
<hr/>
|
||||
<p>@Html.Raw(announcement.Description.Replace(Environment.NewLine, "<br />"))</p>
|
||||
<br/>
|
||||
|
@@ -4,29 +4,25 @@
|
||||
@model WebApp.Pages.AnnouncementsModel
|
||||
@{
|
||||
ViewData["Title"] = "Announcements";
|
||||
List<Announcement> announcements = (List<Announcement>)ViewData["announcements"];
|
||||
List<Announcement> announcements = ((List<Announcement>)ViewData["announcements"]).OrderByDescending(x => x.PublishDate).OrderByDescending(x => x.IsSticky).ToList();
|
||||
int currentPage = @Convert.ToInt32(ViewData["page"]);
|
||||
}
|
||||
|
||||
<a href="./CreateAnnouncement" class="btn btn-primary">Create new announcement</a>
|
||||
|
||||
|
||||
@foreach (Announcement announcement in announcements)
|
||||
{
|
||||
<div class="card" style="display:inline-block; width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@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>
|
||||
<a href="./Announcement?id=@announcement.ID" class="btn btn-primary">More details</a>
|
||||
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN")
|
||||
{
|
||||
@: <a href="./Announcement?id=@announcement.ID" class="btn btn-outline-danger btn-sm">Delete</a>
|
||||
}
|
||||
<div class="mb-3 mt-3">
|
||||
@foreach (Announcement announcement in announcements)
|
||||
{
|
||||
<div class="card" style="display:inline-flex; width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@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>
|
||||
<a href="./Announcement?id=@announcement.ID" class="btn btn-primary">More details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<br />
|
||||
}
|
||||
</div>
|
||||
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
|
30
StudentHouseDashboard/WebApp/Pages/CreateAnnouncement.cshtml
Normal file
30
StudentHouseDashboard/WebApp/Pages/CreateAnnouncement.cshtml
Normal file
@@ -0,0 +1,30 @@
|
||||
@page
|
||||
@model WebApp.Pages.CreateAnnouncementModel
|
||||
@{
|
||||
ViewData["Title"] = "Create announcement";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<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="submit" value="Create" class="btn btn-primary" />
|
||||
</form>
|
@@ -0,0 +1,25 @@
|
||||
using Logic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class CreateAnnouncementModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public Announcement Announcement { get; set; }
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public void 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");
|
||||
}
|
||||
}
|
||||
}
|
@@ -36,7 +36,15 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Announcements">Announcements</a>
|
||||
</li>
|
||||
if (User.IsInRole("ADMIN") || User.IsInRole("MANAGER"))
|
||||
}
|
||||
</ul>
|
||||
@if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
<ul class="navbar-nav">
|
||||
<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">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Register">Create user</a>
|
||||
@@ -45,8 +53,8 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Logout">Logout</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
Reference in New Issue
Block a user