Complaints working, web comments response page, filtering for announcements

This commit is contained in:
Dimitar Byalkov
2023-06-09 04:57:28 +02:00
parent d8e185757d
commit d81450ed21
20 changed files with 336 additions and 48 deletions

View File

@@ -210,7 +210,19 @@ public class CommentRepository : ICommentRepository
public void CreateCommentOnComplaint(User author, string description, string title, DateTime publishDate, int complaintId) public void CreateCommentOnComplaint(User author, string description, string title, DateTime publishDate, int complaintId)
{ {
Comment comment = CreateComment(author, description, title, publishDate);
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "INSERT INTO ComplaintsComments (ComplaintID, CommentID) VALUES (@complaintID, @commentID);";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@complaintID", complaintId);
cmd.Parameters.AddWithValue("@commentID", comment.ID);
int writer = cmd.ExecuteNonQuery();
if (writer != 1)
{
throw new DatabaseOperationException("Database error: Complaint comment not created");
}
}
} }
public List<Comment> GetAllCommentsOnComplaint(int complaintId) public List<Comment> GetAllCommentsOnComplaint(int complaintId)

View File

@@ -68,10 +68,13 @@ namespace Data
List<Complaint> complaints = new List<Complaint>(); List<Complaint> complaints = new List<Complaint>();
UserRepository userRepository = new UserRepository(); UserRepository userRepository = new UserRepository();
User user = userRepository.GetUserById(userId); User user = userRepository.GetUserById(userId);
string sql = "SELECT * FROM Complaints ORDER BY ID DESC OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;"; // Status 3 is Archived status
// no need to list archived complaints for now
// future revision: add an option to see archived complaints?
string sql = "SELECT * FROM Complaints WHERE Status != 3 ORDER BY ID DESC OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
if (user.Role == UserRole.TENANT) if (user.Role == UserRole.TENANT)
{ {
sql = $"SELECT * FROM Complaints WHERE Author = {userId} ORDER BY ID DESC OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;"; sql = $"SELECT * FROM Complaints WHERE Author = {userId} AND Status != 3 ORDER BY ID DESC OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
} }
if (c == null) if (c == null)
{ {

View File

@@ -15,11 +15,15 @@ namespace Logic
this.commentRepository = commentRepository; this.commentRepository = commentRepository;
} }
public void CreateCommentToAnnouncement(User author, string description, string title, DateTime publishDate, int announcementId) public Comment GetCommentById(int id)
{
return commentRepository.GetCommentById(id);
}
public void CreateCommentOnAnnouncement(User author, string description, string title, DateTime publishDate, int announcementId)
{ {
commentRepository.CreateCommentOnAnnouncement(author, description, title, publishDate, announcementId); commentRepository.CreateCommentOnAnnouncement(author, description, title, publishDate, announcementId);
} }
public void CreateResponseToComment(User author, string description, string title, DateTime publishDate, int commentId) public void CreateResponseOnComment(User author, string description, string title, DateTime publishDate, int commentId)
{ {
commentRepository.CreateResponseOnComment(author, description, title, publishDate, commentId); commentRepository.CreateResponseOnComment(author, description, title, publishDate, commentId);
} }
@@ -35,5 +39,13 @@ namespace Logic
{ {
commentRepository.DeleteResponseOnComment(responseId, commentId); commentRepository.DeleteResponseOnComment(responseId, commentId);
} }
public List<Comment> GetAllCommentsOnComplaint(int complaintId)
{
return commentRepository.GetAllCommentsOnComplaint(complaintId);
}
public void CreateCommentOnComplaint(User author, string description, string title, DateTime publishDate, int complaintId)
{
commentRepository.CreateCommentOnComplaint(author, description, title, publishDate, complaintId);
}
} }
} }

View File

@@ -7,6 +7,10 @@ namespace Models
{ {
public class Comment : GenericMessage public class Comment : GenericMessage
{ {
public Comment()
{
}
public Comment(int id, User author, string description, string title, DateTime publishDate) : base(id, author, description, title, publishDate) public Comment(int id, User author, string description, string title, DateTime publishDate) : base(id, author, description, title, publishDate)
{ {
Responses = new List<Comment>(); Responses = new List<Comment>();

View File

@@ -7,13 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp", "WebApp\WebApp.csp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{3967DDCF-BA8E-45CD-895D-626CE346D419}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{3967DDCF-BA8E-45CD-895D-626CE346D419}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logic", "Logic\Logic.csproj", "{1AA9B921-CE97-4139-995E-95435B3110C0}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logic", "Logic\Logic.csproj", "{1AA9B921-CE97-4139-995E-95435B3110C0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data", "Data\Data.csproj", "{FDF2FED1-3113-4BA6-8582-BBE97C301D66}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{FDF2FED1-3113-4BA6-8582-BBE97C301D66}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{F7DC7AD1-7A0A-403B-A535-24267BD07628}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{F7DC7AD1-7A0A-403B-A535-24267BD07628}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{5AB881E8-B8FE-43A5-A74B-40CF15B20AE8}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{5AB881E8-B8FE-43A5-A74B-40CF15B20AE8}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -0,0 +1,35 @@
@page
@using Models;
@model WebApp.Pages.AddCommentModel
@{
ViewData["Title"] = "Add comment";
GenericMessage parentMessage = (GenericMessage)ViewData["parent"];
}
<h1>@ViewData["Title"]</h1>
<h2>Responding to:</h2>
<div class="card" style="display:inline-flex; width: 18rem;">
<div class="card-body">
<h5 class="card-title">
@parentMessage.Title
</h5>
<h6 class="card-subtitle mb-2 text-muted">@parentMessage.Author.Name</h6>
<p class="card-text">@parentMessage.Description.PadRight(100).Substring(0,100).Trim()</p>
</div>
</div>
<form method="post">
<div class="mb-3">
<label asp-for="Comment.Title" class="form-label">Title: </label>
<input asp-for="Comment.Title" class="form-control" />
</div>
<div class="mb-3">
<label asp-for="Comment.Description" class="form-label">Description: </label>
<textarea asp-for="Comment.Description" class="form-control" rows="5"></textarea>
</div>
<input type="hidden" asp-for="Type" />
<input type="hidden" asp-for="ParentId" />
<input type="hidden" asp-for="PreviousPage" />
<input type="submit" value="Create" class="btn btn-primary" />
</form>

View File

@@ -0,0 +1,82 @@
using Logic;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Models;
using System.Security.Claims;
namespace WebApp.Pages
{
public class AddCommentModel : PageModel
{
[BindProperty]
public Comment Comment { get; set; }
[BindProperty]
public string Type { get; set; }
[BindProperty]
public int ParentId { get; set; }
[BindProperty]
public string PreviousPage { get; set; }
private readonly IAnnouncementRepository _announcementRepository;
private readonly ICommentRepository _commentRepository;
private readonly IComplaintRepository _complaintRepository;
private readonly IUserRepository _userRepository;
public AddCommentModel(ICommentRepository commentRepository, IAnnouncementRepository announcementRepository, IComplaintRepository complaintRepository, IUserRepository userRepository)
{
_announcementRepository = announcementRepository;
_commentRepository = commentRepository;
_complaintRepository = complaintRepository;
_userRepository = userRepository;
}
public void OnGet(string t, int id)
{
AnnouncementManager announcementManager = new AnnouncementManager(_announcementRepository);
CommentManager commentManager = new CommentManager(_commentRepository);
ComplaintManager complaintManager = new ComplaintManager(_complaintRepository);
Type = t;
ParentId = id;
PreviousPage = Request.Headers["Referer"].ToString();
switch (Type)
{
case "announcement":
ViewData["parent"] = announcementManager.GetAnnouncementById(ParentId);
break;
case "comment":
ViewData["parent"] = commentManager.GetCommentById(ParentId);
break;
case "complaint":
ViewData["parent"] = complaintManager.GetComplaintById(ParentId);
break;
default:
break;
}
}
public RedirectResult OnPost()
{
CommentManager commentManager = new CommentManager(_commentRepository);
UserManager userManager = new UserManager(_userRepository);
User currentUser = userManager.GetUserById(int.Parse(User.FindFirstValue("id")));
switch (Type)
{
case "announcement":
commentManager.CreateCommentOnAnnouncement(currentUser, Comment.Description, Comment.Title, DateTime.Now, ParentId);
break;
case "comment":
commentManager.CreateResponseOnComment(currentUser, Comment.Description, Comment.Title, DateTime.Now, ParentId);
break;
case "complaint":
commentManager.CreateCommentOnComplaint(currentUser, Comment.Description, Comment.Title, DateTime.Now, ParentId);
break;
default:
break;
}
return Redirect(PreviousPage);
}
}
}

View File

@@ -30,6 +30,7 @@
<p>@Html.Raw(announcement.Description.Replace(Environment.NewLine, "<br />"))</p> <p>@Html.Raw(announcement.Description.Replace(Environment.NewLine, "<br />"))</p>
<br/> <br/>
<h3>Comments</h3> <h3>Comments</h3>
<a href="./AddComment?t=announcement&id=@announcement.ID" class="btn btn-primary">Add comment</a>
@if (announcement.Comments.Count() == 0) @if (announcement.Comments.Count() == 0)
{ {
<p>No comments found</p> <p>No comments found</p>
@@ -55,9 +56,7 @@ else
<h5 class="card-title">@comment.Author.Name @Html.Raw((comment.Author.Role == UserRole.ADMIN || comment.Author.Role == UserRole.MANAGER) ? $"<b>({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(comment.Author.Role.ToString().ToLower())})</b>" : "")</h5> <h5 class="card-title">@comment.Author.Name @Html.Raw((comment.Author.Role == UserRole.ADMIN || comment.Author.Role == UserRole.MANAGER) ? $"<b>({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(comment.Author.Role.ToString().ToLower())})</b>" : "")</h5>
<h6>@comment.PublishDate.ToString("g")</h6> <h6>@comment.PublishDate.ToString("g")</h6>
<p class="card-text">@Html.Raw(comment.Description.Replace(Environment.NewLine, "<br />"))</p> <p class="card-text">@Html.Raw(comment.Description.Replace(Environment.NewLine, "<br />"))</p>
<a class="btn btn-outline-success" href="#">Like</a> <a class="btn btn-outline-primary" href="./AddComment?t=comment&id=@comment.ID">Reply</a>
<a class="btn btn-outline-danger" href="#">Dislike</a>
<a class="btn btn-outline-primary" href="#">Reply</a>
</div> </div>
@if (comment.Responses.Count != 0) @if (comment.Responses.Count != 0)
{ {

View File

@@ -19,7 +19,7 @@ namespace WebApp.Pages
public void OnGet(int id) public void OnGet(int id)
{ {
AnnouncementManager announcementManager = new AnnouncementManager(_announcementRepository); AnnouncementManager announcementManager = new AnnouncementManager(_announcementRepository);
ViewData.Add("announcement", announcementManager.GetAllAnnouncements().First(x => x.ID == id)); ViewData.Add("announcement", announcementManager.GetAnnouncementById(id));
} }
} }
} }

View File

@@ -11,18 +11,29 @@
currentPage = Convert.ToInt32(ViewData["page"]); currentPage = Convert.ToInt32(ViewData["page"]);
} }
} }
<div id="functions">
<a href="./CreateAnnouncement" class="btn btn-primary">Create new announcement</a> <a href="./CreateAnnouncement" class="btn btn-primary">Create new announcement</a>
<form method="get"> <form class="card" method="get">
<div class="form-actions no-color"> <div class="card-body">
<p> <input type="hidden" name="handler" value="filter" />
<input type="hidden" name="handler" value="search" /> <input type="text" name="s" />
<input type="text" name="s" /> <div class="form-check form-check-inline">
<input type="submit" asp-page-handler="Search" value="Search" class="btn btn-default" /> <label class="form-check-label" for="asc">Sort by ascending order</label>
</p> <input class="form-check-input" type="radio" name="asc" value="true" />
</div> </div>
</form> <div class="form-check form-check-inline">
<label class="form-check-label" for="des">Sort by descending order</label>
<input class="form-check-input" type="radio" name="des" value="true" />
</div>
<div class="form-check form-check-inline">
<label class="form-check-label" for="imp">Only important</label>
<input class="form-check-input" type="checkbox" name="imp" value="true" />
</div>
<input type="submit" asp-page-handler="Filter" value="Filter" class="btn btn-default" role="button" />
</div>
</form>
</div>
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
@foreach (Announcement announcement in announcements) @foreach (Announcement announcement in announcements)

View File

@@ -34,10 +34,31 @@ namespace WebApp.Pages
ViewData.Add("count", c); ViewData.Add("count", c);
ViewData.Add("allCount", AnnouncementManager.GetAllAnnouncements().Count); ViewData.Add("allCount", AnnouncementManager.GetAllAnnouncements().Count);
} }
public void OnGetSearch(string s) // search public void OnGetFilter(string s, bool asc, bool des, bool imp) // search, ascending, descending order, isImportant
{ {
AnnouncementManager = new AnnouncementManager(_announcementRepository); AnnouncementManager = new AnnouncementManager(_announcementRepository);
ViewData.Add("announcements", AnnouncementManager.SearchAnnouncements(s)); List<Announcement> announcements = new List<Announcement>();
if (!string.IsNullOrEmpty(s))
{
announcements = AnnouncementManager.SearchAnnouncements(s);
}
else
{
announcements = AnnouncementManager.GetAllAnnouncements();
}
if (imp)
{
announcements = announcements.Where(x => x.IsImportant).ToList();
}
if (asc)
{
announcements = announcements.OrderBy(x => x.PublishDate).ToList();
}
else if (des)
{
announcements = announcements.OrderByDescending(x => x.PublishDate).ToList();
}
ViewData.Add("announcements", announcements);
} }
} }
} }

View File

@@ -0,0 +1,71 @@
@page
@using Models;
@using System.Globalization
@using System.Security.Claims;
@model WebApp.Pages.ComplaintModel
@{
Complaint complaint = (Complaint)ViewData["complaint"];
ViewData["Title"] = $"{complaint.Title}";
}
<h1 @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
</h1>
<p>
Filed @complaint.PublishDate.ToString("g") by @complaint.Author.Name
</p>
<p>
@complaint.Status - @complaint.Severity
</p>
<hr/>
<p>@Html.Raw(complaint.Description.Replace(Environment.NewLine, "<br />"))</p>
<br/>
<h3>Comments</h3>
@if (complaint.Responses.Count() == 0)
{
<p>No comments found</p>
}
else
{
foreach (Comment comment in complaint.Responses)
{
DisplayComment(comment, 0);
}
}
<a href="./AddComment?t=complaint&id=@complaint.ID" class="btn btn-primary">Add reply</a>
@{
void DisplayComment(Comment comment, int level)
{
<div class="d-flex flex-row">
@for (int i = 0; i < level; i++)
{
<a class="me-3" href="#"></a>
}
<div class="card flex-fill">
<div class="card-body">
<h5 class="card-title">@comment.Author.Name @Html.Raw((comment.Author.Role == UserRole.ADMIN || comment.Author.Role == UserRole.MANAGER) ? $"<b>({CultureInfo.CurrentCulture.TextInfo.ToTitleCase(comment.Author.Role.ToString().ToLower())})</b>" : "")</h5>
<h6>@comment.PublishDate.ToString("g")</h6>
<p class="card-text">@Html.Raw(comment.Description.Replace(Environment.NewLine, "<br />"))</p>
</div>
@if (comment.Responses.Count != 0)
{
foreach (var response in comment.Responses)
{
DisplayComment(response, level + 1);
}
}
</div>
</div>
}
}

View 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 ComplaintModel : PageModel
{
private readonly IComplaintRepository _complaintRepository;
public ComplaintModel(IComplaintRepository complaintRepository)
{
_complaintRepository = complaintRepository;
}
public void OnGet(int id)
{
ComplaintManager complaintManager = new ComplaintManager(_complaintRepository);
ViewData.Add("complaint", complaintManager.GetComplaintById(id));
}
}
}

View File

@@ -14,7 +14,7 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label asp-for="Complaint.Severity" class="form-label">Severity: </label> <label asp-for="Complaint.Severity" class="form-label">Severity: </label>
<select asp-for="Complaint.Severity" asp-items="Html.GetEnumSelectList<ComplaintSeverity>()" /> <select asp-for="Complaint.Severity" asp-items="Html.GetEnumSelectList<ComplaintSeverity>()"></select>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label asp-for="Complaint.Description" class="form-label">Description: </label> <label asp-for="Complaint.Description" class="form-label">Description: </label>

View File

@@ -1,4 +1,3 @@
using Data;
using Logic; using Logic;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -13,13 +12,20 @@ namespace WebApp.Pages
{ {
[BindProperty] [BindProperty]
public Complaint Complaint { get; set; } public Complaint Complaint { get; set; }
private readonly IComplaintRepository _complaintRepository;
private readonly IUserRepository _userRepository;
public CreateComplaintModel(IComplaintRepository complaintRepository, IUserRepository userRepository)
{
_complaintRepository = complaintRepository;
_userRepository = userRepository;
}
public void OnGet() public void OnGet()
{ {
} }
public IActionResult OnPost() public IActionResult OnPost()
{ {
ComplaintManager complaintManager = new ComplaintManager(new ComplaintRepository()); ComplaintManager complaintManager = new ComplaintManager(_complaintRepository);
UserManager userManager = new UserManager(new UserRepository()); UserManager userManager = new UserManager(_userRepository);
User user = userManager.GetUserById(int.Parse(User.FindFirstValue("id"))); User user = userManager.GetUserById(int.Parse(User.FindFirstValue("id")));
complaintManager.CreateComplaint(Complaint.Title, Complaint.Description, user, DateTime.Now, ComplaintStatus.FILED, Complaint.Severity); complaintManager.CreateComplaint(Complaint.Title, Complaint.Description, user, DateTime.Now, ComplaintStatus.FILED, Complaint.Severity);
return RedirectToPage("Complaints"); return RedirectToPage("Complaints");

View File

@@ -124,7 +124,7 @@ namespace WinForms
private void btnCreateComment_Click(object sender, EventArgs e) private void btnCreateComment_Click(object sender, EventArgs e)
{ {
CommentForm form = new CommentForm(null, false, currentUser, true, announcement.ID); CommentForm form = new CommentForm(null, false, currentUser, "announcement", announcement.ID);
form.ShowDialog(); form.ShowDialog();
RefreshComments(); RefreshComments();
} }

View File

@@ -17,7 +17,8 @@ namespace WinForms
{ {
Comment? comment; Comment? comment;
User currentUser; User currentUser;
bool announcementResponse; string responseType;
bool complaint;
int parentId; int parentId;
public CommentForm(Comment? comment, bool readOnly, User currentUser) public CommentForm(Comment? comment, bool readOnly, User currentUser)
{ {
@@ -62,9 +63,9 @@ namespace WinForms
lblAuthor.Text = $"Created by: {currentUser.Name}"; lblAuthor.Text = $"Created by: {currentUser.Name}";
} }
} }
public CommentForm(Comment? comment, bool readOnly, User? currentUser, bool announcementResponse, int parentId) : this(comment, readOnly, currentUser) public CommentForm(Comment? comment, bool readOnly, User? currentUser, string responseType, int parentId) : this(comment, readOnly, currentUser)
{ {
this.announcementResponse = announcementResponse; this.responseType = responseType;
this.parentId = parentId; this.parentId = parentId;
} }
private void btnSave_Click(object sender, EventArgs e) private void btnSave_Click(object sender, EventArgs e)
@@ -77,13 +78,19 @@ namespace WinForms
} }
if (this.comment == null) if (this.comment == null)
{ {
if (announcementResponse) switch (responseType)
{ {
commentManager.CreateCommentToAnnouncement(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); case "announcement":
} commentManager.CreateCommentOnAnnouncement(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId);
else break;
{ case "comment":
commentManager.CreateResponseToComment(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId); commentManager.CreateResponseOnComment(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId);
break;
case "complaint":
commentManager.CreateCommentOnComplaint(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId);
break;
default:
break;
} }
} }
else else
@@ -142,7 +149,7 @@ namespace WinForms
private void btnCreateComment_Click(object sender, EventArgs e) private void btnCreateComment_Click(object sender, EventArgs e)
{ {
CommentForm form = new CommentForm(null, false, currentUser, false, comment.ID); CommentForm form = new CommentForm(null, false, currentUser, "comment", comment.ID);
form.ShowDialog(); form.ShowDialog();
RefreshComments(); RefreshComments();
} }

View File

@@ -132,7 +132,7 @@ namespace WinForms
private void btnCreateComment_Click(object sender, EventArgs e) private void btnCreateComment_Click(object sender, EventArgs e)
{ {
CommentForm form = new CommentForm(null, false, currentUser, true, complaint.ID); CommentForm form = new CommentForm(null, false, currentUser, "complaint", complaint.ID);
form.ShowDialog(); form.ShowDialog();
RefreshComments(); RefreshComments();
} }

View File

@@ -202,8 +202,8 @@ namespace WinForms
if (MessageBox.Show($"Are you sure you want to archive\n{currentComplaint.Title}\nCreated at {currentComplaint.PublishDate.ToString("g")} by {currentComplaint.Author.Name}", if (MessageBox.Show($"Are you sure you want to archive\n{currentComplaint.Title}\nCreated at {currentComplaint.PublishDate.ToString("g")} by {currentComplaint.Author.Name}",
"Archive complaint", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) "Archive complaint", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
AnnouncementManager announcementManager = new AnnouncementManager(new AnnouncementRepository()); ComplaintManager complaintManager = new ComplaintManager(new ComplaintRepository());
announcementManager.DeleteAnnouncement(currentComplaint.ID); complaintManager.UpdateComplaint(currentComplaint.ID, currentComplaint.Title, currentComplaint.Description, ComplaintStatus.ARCHIVED, currentComplaint.Severity);
} }
RefreshLists(); RefreshLists();
} }

View File

@@ -19,10 +19,10 @@ namespace WinForms
{ {
MessageBox.Show("Wrong username or password", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Wrong username or password", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
/*else if (user.Role == UserRole.TENANT) else if (user.Role == UserRole.TENANT)
{ {
MessageBox.Show("This application is for the management. Please use the web portal", "Access denied", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("This application is for the management. Please use the web portal!", "Access denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
}*/ }
else else
{ {
Dashboard dashboard = new Dashboard(this, user); Dashboard dashboard = new Dashboard(this, user);