Refactoring: Added interfaces, custom exceptions, UserManager unit tests, dependency injection/inversion; Regex match search by date, keywords
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class Announcement : GenericMessage, IVotable
|
||||
public class Announcement : GenericMessage
|
||||
{
|
||||
public Announcement(int id, User author, string description, string title, DateTime publishDate, bool isImportant, bool isSticky) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
@@ -31,16 +31,6 @@ namespace Models
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void DownVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Title} ({PublishDate.ToString("g")} - {Author.Name})";
|
||||
|
@@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class Comment : GenericMessage, IVotable
|
||||
public class Comment : GenericMessage
|
||||
{
|
||||
public Comment(int id, User author, string description, string title, DateTime publishDate) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
@@ -13,15 +13,6 @@ namespace Models
|
||||
}
|
||||
|
||||
public List<Comment> Responses { get; set; }
|
||||
public void DownVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Author.Name} ({PublishDate.ToString("g")}) - {Description.PadRight(100).Trim()}";
|
||||
|
@@ -7,11 +7,6 @@ namespace Models
|
||||
{
|
||||
public abstract class GenericMessage
|
||||
{
|
||||
private User author;
|
||||
private string description;
|
||||
private string title;
|
||||
private DateTime publishDate;
|
||||
|
||||
protected GenericMessage(int id, User author, string description, string title, DateTime publishDate)
|
||||
{
|
||||
ID = id;
|
||||
@@ -31,23 +26,19 @@ namespace Models
|
||||
|
||||
public User Author
|
||||
{
|
||||
get => author;
|
||||
set => author = value;
|
||||
get;set;
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
set => description = value;
|
||||
get;set;
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get => title;
|
||||
set => title = value;
|
||||
get;set;
|
||||
}
|
||||
public DateTime PublishDate
|
||||
{
|
||||
get => publishDate;
|
||||
set => publishDate = value;
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public interface IVotable
|
||||
{
|
||||
void UpVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
void DownVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,10 +9,6 @@ namespace Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
private int id;
|
||||
private string name;
|
||||
private string password;
|
||||
private UserRole role;
|
||||
|
||||
public User(int id, string name, string password, UserRole role)
|
||||
{
|
||||
@@ -23,29 +19,26 @@ namespace Models
|
||||
}
|
||||
public User()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
public int ID
|
||||
{
|
||||
get; private set;
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => name = value;
|
||||
get; set;
|
||||
}
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
public string Password
|
||||
{
|
||||
get => password;
|
||||
set => password = value;
|
||||
get; set;
|
||||
}
|
||||
public UserRole Role
|
||||
{
|
||||
get => role;
|
||||
set => role = value;
|
||||
get; set;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
|
Reference in New Issue
Block a user