Basic announcements added
This commit is contained in:
@@ -2,21 +2,27 @@
|
||||
@using StudentHouseDashboard.Models;
|
||||
@model WebApp.Pages.AnnouncementModel
|
||||
@{
|
||||
User user = (User)ViewData["user"];
|
||||
ViewData["Title"] = $"User {user.Name}";
|
||||
Announcement announcement = (Announcement)ViewData["announcement"];
|
||||
ViewData["Title"] = $"{announcement.Title}";
|
||||
}
|
||||
<h1>@user.Name</h1>
|
||||
<h1>@announcement.Title</h1>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<p>Name: </p>
|
||||
<p>Password: </p>
|
||||
<p>Role: </p>
|
||||
<p>Title: </p>
|
||||
<p>Author: </p>
|
||||
<p>Description: </p>
|
||||
<p>Date: </p>
|
||||
<p>Important: </p>
|
||||
<p>Pinned: </p>
|
||||
</div>
|
||||
<div class="col">
|
||||
<p>@user.Name</p>
|
||||
<p>@user.Password</p>
|
||||
<p>@user.Role.ToString()</p>
|
||||
<p>@announcement.Title</p>
|
||||
<p>@announcement.Author.Name</p>
|
||||
<p>@announcement.Description</p>
|
||||
<p>@announcement.PublishDate.ToString("g")</p>
|
||||
<p>@announcement.IsImportant.ToString()</p>
|
||||
<p>@announcement.IsSticky.ToString()</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using StudentHouseDashboard.Managers;
|
||||
using StudentHouseDashboard.Models;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
@@ -10,8 +11,8 @@ namespace WebApp.Pages
|
||||
{
|
||||
public void OnGet(int id)
|
||||
{
|
||||
UserManager userManager = new UserManager();
|
||||
ViewData.Add("user", userManager.GetUserById(id));
|
||||
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||
ViewData.Add("announcement", announcementManager.GetAllAnnouncements().Where(x => x.ID == id).First());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,20 +1,25 @@
|
||||
@page
|
||||
@using StudentHouseDashboard.Models;
|
||||
@using System.Security.Claims;
|
||||
@model WebApp.Pages.AnnouncementsModel
|
||||
@{
|
||||
ViewData["Title"] = "Announcements";
|
||||
List<User> users = (List<User>)ViewData["users"];
|
||||
List<Announcement> announcements = (List<Announcement>)ViewData["announcements"];
|
||||
int currentPage = @Convert.ToInt32(ViewData["page"]);
|
||||
}
|
||||
|
||||
@foreach (User user in users)
|
||||
@foreach (Announcement announcement in announcements)
|
||||
{
|
||||
<div class="card" style="display:inline-block; width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@user.Role.ToString()</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">@user.Name</h6>
|
||||
<p class="card-text">@user.Password</p>
|
||||
<a href="./Announcement?id=@user.ID" class="btn btn-primary">More details</a>
|
||||
<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</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>
|
||||
</div>
|
||||
}
|
||||
@@ -37,7 +42,7 @@
|
||||
@: <li class="page-item"><a class="page-link" href="./Announcements?p=@(currentPage - 1)">@(currentPage - 1)</a></li>
|
||||
}
|
||||
<li class="page-item"><a class="page-link">@currentPage</a></li>
|
||||
@if (users.Count == 0)
|
||||
@if (announcements.Count == 0)
|
||||
{
|
||||
@: <li class="page-item disabled">
|
||||
}
|
||||
|
@@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using StudentHouseDashboard.Managers;
|
||||
using StudentHouseDashboard.Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
@@ -9,17 +11,16 @@ namespace WebApp.Pages
|
||||
public class AnnouncementsModel : PageModel
|
||||
{
|
||||
public AnnouncementManager AnnouncementManager { get; set; }
|
||||
public UserManager UserManager { get; set; }
|
||||
public void OnGet(int? p, int? c)
|
||||
{
|
||||
UserManager = new UserManager();
|
||||
AnnouncementManager = new AnnouncementManager();
|
||||
if (p == null || p < 1)
|
||||
{
|
||||
p = 1;
|
||||
}
|
||||
ViewData.Add("users", UserManager.GetUsersByPage(p - 1, c));
|
||||
ViewData.Add("announcements", AnnouncementManager.GetAnnouncementsByPage(p - 1, c));
|
||||
ViewData.Add("page", p);
|
||||
ViewData.Add("allCount", UserManager.GetAllUsers().Count());
|
||||
ViewData.Add("allCount", AnnouncementManager.GetAllAnnouncements().Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user