-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathChatEntity.cs
More file actions
120 lines (94 loc) · 3.18 KB
/
ChatEntity.cs
File metadata and controls
120 lines (94 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using FluentValidation;
using MangoAPI.Domain.Enums;
using System;
using System.Collections.Generic;
using Uuids;
namespace MangoAPI.Domain.Entities;
public sealed class ChatEntity
{
public Guid Id { get; private set; }
public string Title { get; private set; }
public CommunityType CommunityType { get; private set; }
public string Description { get; private set; }
public string ImageFileName { get; private set; }
public DateTime CreatedAt { get; private set; }
public int MembersCount { get; private set; }
public string LastMessageAuthor { get; private set; }
public string LastMessageText { get; private set; }
public DateTime? LastMessageTime { get; private set; }
public Guid? LastMessageId { get; private set; }
public ICollection<MessageEntity> Messages => _messages;
private readonly List<MessageEntity> _messages;
public ICollection<UserChatEntity> ChatUsers => _chatUsers;
private readonly List<UserChatEntity> _chatUsers;
private ChatEntity()
{
}
private ChatEntity(
string title,
CommunityType communityType,
string description,
string imageFileName,
DateTime createdAt,
int membersCount)
{
Title = title;
CommunityType = communityType;
Description = description;
ImageFileName = imageFileName;
CreatedAt = createdAt;
MembersCount = membersCount;
_messages = new List<MessageEntity>();
_chatUsers = new List<UserChatEntity>();
Id = Uuid.NewMySqlOptimized().ToGuidByteLayout();
new ChatEntityValidator().ValidateAndThrow(this);
}
public static ChatEntity Create(
string title,
CommunityType communityType,
string description,
string image,
DateTime createdAt,
int membersCount)
{
var newChat = new ChatEntity(title, communityType, description, image, createdAt, membersCount);
return newChat;
}
public void IncrementMembersCount(int value)
{
MembersCount += value;
new ChatEntityValidator().ValidateAndThrow(this);
}
public void ChangeChatImage(string fileName)
{
ImageFileName = fileName;
new ChatEntityValidator().ValidateAndThrow(this);
}
public void UpdateLastMessage(
string lastMessageAuthor,
string lastMessageText,
DateTime? lastMessageDate,
Guid? lastMessageId)
{
UpdateLastMessage(lastMessageText, lastMessageDate);
LastMessageAuthor = lastMessageAuthor;
LastMessageId = lastMessageId;
new ChatEntityValidator().ValidateAndThrow(this);
}
public void UpdateLastMessage(string lastMessageText, DateTime? lastMessageDate)
{
LastMessageText = lastMessageText;
LastMessageTime = lastMessageDate;
new ChatEntityValidator().ValidateAndThrow(this);
}
public void UpdateTitle(string title)
{
Title = title;
new ChatEntityValidator().ValidateAndThrow(this);
}
public void UpdateDescription(string newDescription)
{
Description = newDescription;
new ChatEntityValidator().ValidateAndThrow(this);
}
}