-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathUserEntity.cs
More file actions
134 lines (101 loc) · 3.54 KB
/
UserEntity.cs
File metadata and controls
134 lines (101 loc) · 3.54 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using FluentValidation;
using System.Collections.Generic;
using MangoAPI.Domain.Enums;
using System;
using Uuids;
namespace MangoAPI.Domain.Entities;
public sealed class UserEntity
{
public Guid Id { get; private set; }
public string Username { get; private set; }
public byte[] PasswordHash { get; private set; }
public byte[] PasswordSalt { get; private set; }
public string DisplayName { get; private set; }
public string ImageFileName { get; private set; }
public string Bio { get; private set; }
public string Website { get; private set; }
public DateTime? Birthday { get; private set; }
public string Address { get; private set; }
public DisplayNameColour DisplayNameColour { get; private set; }
public PersonalInformationEntity PersonalInformation { get; private set; }
public IReadOnlyCollection<SessionEntity> Sessions => _sessions;
private readonly List<SessionEntity> _sessions;
public IReadOnlyCollection<MessageEntity> Messages => _messages;
private readonly List<MessageEntity> _messages;
public IReadOnlyCollection<UserChatEntity> UserChats => _userChats;
private readonly List<UserChatEntity> _userChats;
public IReadOnlyCollection<ContactEntity> Contacts => _contacts;
private readonly List<ContactEntity> _contacts;
private UserEntity()
{
}
private UserEntity(
string username,
byte[] passwordHash,
byte[] passwordSalt,
string displayName,
string imageFileName,
DisplayNameColour displayNameColour)
{
Id = Uuid.NewMySqlOptimized().ToGuidByteLayout();
_sessions = new List<SessionEntity>();
_messages = new List<MessageEntity>();
_userChats = new List<UserChatEntity>();
_contacts = new List<ContactEntity>();
Username = username;
PasswordHash = passwordHash;
PasswordSalt = passwordSalt;
DisplayName = displayName;
ImageFileName = imageFileName;
DisplayNameColour = displayNameColour;
new UserEntityValidator().ValidateAndThrow(this);
}
public static UserEntity Create(
string username,
byte[] passwordHash,
byte[] passwordSalt,
string displayName,
string imageFileName,
DisplayNameColour displayNameColour)
{
var user = new UserEntity(
username,
passwordHash,
passwordSalt,
displayName,
imageFileName,
displayNameColour);
return user;
}
public void UpdateProfilePicture(string imageFileName)
{
ImageFileName = imageFileName;
new UserEntityValidator().ValidateAndThrow(this);
}
public void SetDisplayName(string displayName)
{
DisplayName = displayName;
new UserEntityValidator().ValidateAndThrow(this);
}
public void UpdateUserData(string bio, string website, DateTime? birthday, string address, string username)
{
Bio = bio;
Website = website;
Birthday = birthday;
Address = address;
Username = username;
new UserEntityValidator().ValidateAndThrow(this);
}
public void UpdatePassword(byte[] passwordHash, byte[] passwordSalt)
{
PasswordHash = passwordHash;
PasswordSalt = passwordSalt;
new UserEntityValidator().ValidateAndThrow(this);
}
public void UpdateBioAndLocation(string bio, string address)
{
Bio = bio;
Address = address;
new UserEntityValidator().ValidateAndThrow(this);
}
}