Refactoring - split data, logic and model layers; custom network exception
This commit is contained in:
45
StudentHouseDashboard/Models/Announcement.cs
Normal file
45
StudentHouseDashboard/Models/Announcement.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class Announcement : GenericMessage, IVotable
|
||||
{
|
||||
public Announcement(int id, User author, string description, string title, DateTime publishDate, bool isImportant, bool isSticky) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
IsImportant = isImportant;
|
||||
IsSticky = isSticky;
|
||||
}
|
||||
|
||||
public List<Comment> Comments
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public bool IsImportant
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public bool IsSticky
|
||||
{
|
||||
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})";
|
||||
}
|
||||
}
|
||||
}
|
76
StudentHouseDashboard/Models/ClassDiagram1.cd
Normal file
76
StudentHouseDashboard/Models/ClassDiagram1.cd
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||
<Class Name="StudentHouseDashboard.Models.Announcement" BaseTypeListCollapsed="true">
|
||||
<Position X="8.25" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIhA=</HashCode>
|
||||
<FileName>Models\Announcement.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Comment" BaseTypeListCollapsed="true">
|
||||
<Position X="10" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA=</HashCode>
|
||||
<FileName>Models\Comment.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Complaint" BaseTypeListCollapsed="true">
|
||||
<Position X="4.75" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAA=</HashCode>
|
||||
<FileName>Models\Complaint.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Event" BaseTypeListCollapsed="true">
|
||||
<Position X="6.5" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAEAAAAA=</HashCode>
|
||||
<FileName>Models\Event.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.User">
|
||||
<Position X="11.75" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAEAAAABQAAAAEAAACAAAAAgAAAAA=</HashCode>
|
||||
<FileName>Models\User.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.GenericMessage">
|
||||
<Position X="8.25" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAQAAoAEAAqAAAAIAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\GenericMessage.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Interface Name="StudentHouseDashboard.Models.IVotable">
|
||||
<Position X="10" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA=</HashCode>
|
||||
<FileName>Models\IVotable.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Interface>
|
||||
<Enum Name="StudentHouseDashboard.Models.ComplaintSeverity">
|
||||
<Position X="4.75" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAEgAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\ComplaintSeverity.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Enum Name="StudentHouseDashboard.Models.ComplaintStatus">
|
||||
<Position X="6.5" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAABAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAA=</HashCode>
|
||||
<FileName>Models\ComplaintStatus.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Enum Name="StudentHouseDashboard.Models.UserRole">
|
||||
<Position X="11.75" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAQAAAAAAAAAAAAAAAAAAAAAQAAAAQAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\UserRole.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Font Name="Segoe UI" Size="9" />
|
||||
</ClassDiagram>
|
30
StudentHouseDashboard/Models/Comment.cs
Normal file
30
StudentHouseDashboard/Models/Comment.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class Comment : GenericMessage, IVotable
|
||||
{
|
||||
public Comment(int id, User author, string description, string title, DateTime publishDate) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
Responses = new List<Comment>();
|
||||
}
|
||||
|
||||
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()}";
|
||||
}
|
||||
}
|
||||
}
|
31
StudentHouseDashboard/Models/Complaint.cs
Normal file
31
StudentHouseDashboard/Models/Complaint.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class Complaint : GenericMessage
|
||||
{
|
||||
public Complaint(int id, User author, string description, string title, DateTime publishDate, ComplaintStatus status, ComplaintSeverity severity) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
Status = status;
|
||||
Severity = severity;
|
||||
}
|
||||
|
||||
public ComplaintStatus Status
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public ComplaintSeverity Severity
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public List<Comment> Responses
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
}
|
||||
}
|
15
StudentHouseDashboard/Models/ComplaintSeverity.cs
Normal file
15
StudentHouseDashboard/Models/ComplaintSeverity.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public enum ComplaintSeverity
|
||||
{
|
||||
LOW,
|
||||
NORMAL,
|
||||
HIGH,
|
||||
URGENT
|
||||
}
|
||||
}
|
15
StudentHouseDashboard/Models/ComplaintStatus.cs
Normal file
15
StudentHouseDashboard/Models/ComplaintStatus.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public enum ComplaintStatus
|
||||
{
|
||||
FILED,
|
||||
UNDER_REVIEW,
|
||||
SOLVED,
|
||||
ARCHIVED
|
||||
}
|
||||
}
|
26
StudentHouseDashboard/Models/Event.cs
Normal file
26
StudentHouseDashboard/Models/Event.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public class Event : GenericMessage
|
||||
{
|
||||
public Event(int id, User author, string description, string title, DateTime publishDate, DateTime startDate, DateTime endDate) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
StartDate = startDate;
|
||||
EndDate = endDate;
|
||||
}
|
||||
|
||||
public DateTime StartDate
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public DateTime EndDate
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
}
|
||||
}
|
50
StudentHouseDashboard/Models/GenericMessage.cs
Normal file
50
StudentHouseDashboard/Models/GenericMessage.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
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;
|
||||
Author = author;
|
||||
Description = description;
|
||||
Title = title;
|
||||
PublishDate = publishDate;
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public User Author
|
||||
{
|
||||
get => author;
|
||||
set => author = value;
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
set => description = value;
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get => title;
|
||||
set => title = value;
|
||||
}
|
||||
public DateTime PublishDate
|
||||
{
|
||||
get => publishDate;
|
||||
set => publishDate = value;
|
||||
}
|
||||
}
|
||||
}
|
19
StudentHouseDashboard/Models/IVotable.cs
Normal file
19
StudentHouseDashboard/Models/IVotable.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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
StudentHouseDashboard/Models/Models.csproj
Normal file
9
StudentHouseDashboard/Models/Models.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
55
StudentHouseDashboard/Models/User.cs
Normal file
55
StudentHouseDashboard/Models/User.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
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)
|
||||
{
|
||||
ID = id;
|
||||
Name = name;
|
||||
Password = password;
|
||||
Role = role;
|
||||
}
|
||||
public User()
|
||||
{
|
||||
|
||||
}
|
||||
public int ID
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => name = value;
|
||||
}
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
public string Password
|
||||
{
|
||||
get => password;
|
||||
set => password = value;
|
||||
}
|
||||
public UserRole Role
|
||||
{
|
||||
get => role;
|
||||
set => role = value;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{ID}: {Name} ({Role})";
|
||||
}
|
||||
}
|
||||
}
|
18
StudentHouseDashboard/Models/UserRole.cs
Normal file
18
StudentHouseDashboard/Models/UserRole.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
public enum UserRole
|
||||
{
|
||||
[Display(Name = "Tenant")]
|
||||
TENANT,
|
||||
[Display(Name = "Manager")]
|
||||
MANAGER,
|
||||
[Display(Name = "Administrator")]
|
||||
ADMIN
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user