Refactoring: Added interfaces, custom exceptions, UserManager unit tests, dependency injection/inversion; Regex match search by date, keywords

This commit is contained in:
Dimitar Byalkov
2023-06-06 17:52:36 +02:00
parent 180b261d37
commit 53c42a35d8
43 changed files with 668 additions and 211 deletions

View File

@@ -1,4 +1,5 @@
using Logic;
using Data;
using Logic;
using Models;
using System;
using System.Collections.Generic;
@@ -43,13 +44,10 @@ namespace WinForms
btnViewComment.Enabled = false;
}
if (comment != null && currentUser != null)
if (comment != null && currentUser != null && currentUser.ID != comment.Author.ID)
{
if (currentUser.ID != comment.Author.ID)
{
// restriction: only edit personal comments
readOnly = true;
}
// restriction: only edit personal comments
readOnly = true;
}
if (readOnly)
@@ -71,7 +69,7 @@ namespace WinForms
}
private void btnSave_Click(object sender, EventArgs e)
{
CommentManager commentManager = new CommentManager();
CommentManager commentManager = new CommentManager(new CommentRepository());
if (string.IsNullOrEmpty(tbTitle.Text) || string.IsNullOrEmpty(tbDescription.Text))
{
MessageBox.Show("Please enter a title and comment text");
@@ -135,7 +133,7 @@ namespace WinForms
if (MessageBox.Show($"Are you sure you want to delete\n{currentResponse.Title}\nCreated at {currentResponse.PublishDate.ToString("g")} by {currentResponse.Author.Name}",
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
CommentManager commentManager = new CommentManager();
CommentManager commentManager = new CommentManager(new CommentRepository());
commentManager.DeleteResponseOnComment(currentResponse.ID, comment.ID);
}
RefreshComments();