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 nie może być pusty."); } if (Email == email) { return; } Email = email; UpdatedAt = DateTime.UtcNow; } public void SetName(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new Exception("Imię nie może być puste."); } if (Name == name) { return; } Name = name; UpdatedAt = DateTime.UtcNow; } public void SetSurname(string surname) { if (string.IsNullOrWhiteSpace(surname)) { throw new Exception("Nazwisko nie może być puste."); } if (Surname == surname) { return; } Surname = surname; UpdatedAt = DateTime.UtcNow; } public void SetLogin(string login) { if (string.IsNullOrWhiteSpace(login)) { throw new Exception("Login nie może być pusty."); } if (Login == login) { return; } Login = login; UpdatedAt = DateTime.UtcNow; } public void SetPassword(string password) { if (string.IsNullOrWhiteSpace(password)) { throw new Exception("Hasło nie może być puste."); } if (Password == password) { return; } Password = password; UpdatedAt = DateTime.UtcNow; } } }