Test plan incomplete, basic compaints support
This commit is contained in:
76
StudentHouseDashboard/WebApp/Pages/Complaints.cshtml
Normal file
76
StudentHouseDashboard/WebApp/Pages/Complaints.cshtml
Normal file
@@ -0,0 +1,76 @@
|
||||
@page
|
||||
@using Models;
|
||||
@using System.Security.Claims;
|
||||
@model WebApp.Pages.ComplaintsModel
|
||||
@{
|
||||
ViewData["Title"] = "Complaints";
|
||||
List<Complaint> complaints = ((List<Complaint>)ViewData["complaints"]).ToList();
|
||||
int currentPage = 0;
|
||||
if (ViewData["page"] != null)
|
||||
{
|
||||
currentPage = Convert.ToInt32(ViewData["page"]);
|
||||
}
|
||||
}
|
||||
|
||||
<a href="./CreateComplaint" class="btn btn-primary">Create new complaint</a>
|
||||
|
||||
<div class="mb-3 mt-3">
|
||||
@foreach (Complaint complaint in complaints)
|
||||
{
|
||||
<div class="card" style="display:inline-flex; width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" @if (complaint.Severity == ComplaintSeverity.URGENT)
|
||||
{
|
||||
@: style="color: red;"
|
||||
}
|
||||
else if (complaint.Severity == ComplaintSeverity.HIGH)
|
||||
{
|
||||
@: style="color: orange;"
|
||||
}
|
||||
@if (complaint.Severity == ComplaintSeverity.LOW)
|
||||
{
|
||||
@: style="color: darkgreen;"
|
||||
}>@complaint.Title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">@complaint.Status</h6>
|
||||
<h6 class="card-subtitle mb-2 text-muted">@complaint.Author.Name</h6>
|
||||
<p class="card-text">@complaint.Description.PadRight(100).Substring(0,100).Trim()</p>
|
||||
<a href="./complaint?id=@complaint.ID" class="btn btn-primary">More details</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (ViewData["page"] != null)
|
||||
{
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
@if (currentPage <= 1)
|
||||
{
|
||||
@: <li class="page-item disabled">
|
||||
@: <a class="page-link" tabindex="-1">Previous</a>
|
||||
@: </li>
|
||||
}
|
||||
else
|
||||
{
|
||||
@: <li class="page-item">
|
||||
@: <a class="page-link" href="./complaints?p=@(currentPage - 1)" tabindex="-1">Previous</a>
|
||||
@: </li>
|
||||
@: <li class="page-item"><a class="page-link" href="./complaints?p=@(currentPage - 1)">@(currentPage - 1)</a></li>
|
||||
}
|
||||
<li class="page-item"><a class="page-link">@currentPage</a>
|
||||
@if (complaints.Count == 0 || complaints.Count < Convert.ToInt32(ViewData["count"]))
|
||||
{
|
||||
@: <li class="page-item disabled">
|
||||
@: <a class="page-link">Next</a>
|
||||
@: </li>
|
||||
}
|
||||
else
|
||||
{
|
||||
@: <li class="page-item"><a class="page-link" href="./complaints?p=@(currentPage + 1)">@(currentPage + 1)</a></li>
|
||||
@: <li class="page-item">
|
||||
@: <a class="page-link" href="./complaints?p=@(currentPage + 1)">Next</a>
|
||||
@: </li>
|
||||
}
|
||||
</ul>
|
||||
</nav>
|
||||
}
|
38
StudentHouseDashboard/WebApp/Pages/Complaints.cshtml.cs
Normal file
38
StudentHouseDashboard/WebApp/Pages/Complaints.cshtml.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Logic;
|
||||
using Models;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
[Authorize]
|
||||
public class ComplaintsModel : PageModel
|
||||
{
|
||||
public ComplaintManager ComplaintManager { get; set; }
|
||||
private readonly IComplaintRepository _complaintRepository;
|
||||
|
||||
public ComplaintsModel(IComplaintRepository complaintRepository)
|
||||
{
|
||||
_complaintRepository = complaintRepository;
|
||||
}
|
||||
|
||||
public void OnGet(int? p, int? c) // page, count
|
||||
{
|
||||
ComplaintManager = new ComplaintManager(_complaintRepository);
|
||||
if (!(p < 0))
|
||||
{
|
||||
p = 1;
|
||||
}
|
||||
if (!(c < 1))
|
||||
{
|
||||
c = 10;
|
||||
}
|
||||
ViewData.Add("complaints", ComplaintManager.GetComplaintsByPage(int.Parse(User.FindFirstValue("id")), p.Value - 1, c.Value));
|
||||
ViewData.Add("page", p);
|
||||
ViewData.Add("count", c);
|
||||
ViewData.Add("allCount", ComplaintManager.GetAllComplaints().Count);
|
||||
}
|
||||
}
|
||||
}
|
24
StudentHouseDashboard/WebApp/Pages/CreateComplaint.cshtml
Normal file
24
StudentHouseDashboard/WebApp/Pages/CreateComplaint.cshtml
Normal file
@@ -0,0 +1,24 @@
|
||||
@page
|
||||
@using Models;
|
||||
@model WebApp.Pages.CreateComplaintModel
|
||||
@{
|
||||
ViewData["Title"] = "Create complaint";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="Complaint.Title" class="form-label">Title: </label>
|
||||
<input asp-for="Complaint.Title" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Complaint.Severity" class="form-label">Severity: </label>
|
||||
<select asp-for="Complaint.Severity" asp-items="Html.GetEnumSelectList<ComplaintSeverity>()" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Complaint.Description" class="form-label">Description: </label>
|
||||
<textarea asp-for="Complaint.Description" class="form-control" rows="5"></textarea>
|
||||
</div>
|
||||
<input type="submit" value="Create" class="btn btn-primary" />
|
||||
</form>
|
28
StudentHouseDashboard/WebApp/Pages/CreateComplaint.cshtml.cs
Normal file
28
StudentHouseDashboard/WebApp/Pages/CreateComplaint.cshtml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Data;
|
||||
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 CreateComplaintModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public Complaint Complaint { get; set; }
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
ComplaintManager complaintManager = new ComplaintManager(new ComplaintRepository());
|
||||
UserManager userManager = new UserManager(new UserRepository());
|
||||
User user = userManager.GetUserById(int.Parse(User.FindFirstValue("id")));
|
||||
complaintManager.CreateComplaint(Complaint.Title, Complaint.Description, user, DateTime.Now, ComplaintStatus.FILED, Complaint.Severity);
|
||||
return RedirectToPage("Complaints");
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,6 +27,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Announcements">Announcements</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Complaints">Complaints</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
|
Reference in New Issue
Block a user