using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Serwer.Core.Domain { public class User { public Guid Id { get; protected set; } public string Email { get; protected set; } public string Name { get; protected set; } public string Surname { get; protected set; } public string Login { get; protected set; } public string Password { get; protected set; } public DateTime CreatedAt { get; protected set; } public DateTime UpdatedAt { get; protected set; } protected User() { } public User(Guid id, string email, string name, string surname, string login, string password) { Id = id; SetEmail(email); SetName(name); SetSurname(surname); SetLogin(login); SetPassword(password); CreatedAt = DateTime.UtcNow; } public void SetEmail(string email) { if (string.IsNullOrWhiteSpace(email)) { throw new Exception("Email cannot be empty"); } if (Email == email) { return; } Email = email; UpdatedAt = DateTime.UtcNow; } public void SetName(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new Exception("Name cannot be empty"); } if (Name == name) { return; } Name = name; UpdatedAt = DateTime.UtcNow; } public void SetSurname(string surname) { if (string.IsNullOrWhiteSpace(surname)) { throw new Exception("Surname cannot be empty"); } if (Surname == surname) { return; } Surname = surname; UpdatedAt = DateTime.UtcNow; } public void SetLogin(string login) { if (string.IsNullOrWhiteSpace(login)) { throw new Exception("Login cannot be empty"); } if (Login == login) { return; } Login = login; UpdatedAt = DateTime.UtcNow; } public void SetPassword(string password) { if (string.IsNullOrWhiteSpace(password)) { throw new Exception("Password cannot be empty"); } if (Password == password) { return; } Password = password; UpdatedAt = DateTime.UtcNow; } } }