Poszukiwacz/Serwer/Serwer.Core/Domain/User.cs

108 lines
2.7 KiB
C#
Raw Normal View History

2020-12-06 16:01:38 +01:00
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() { }
2020-12-18 16:04:07 +01:00
public User(Guid id, string email, string name, string surname, string login, string password)
2020-12-06 16:01:38 +01:00
{
2020-12-18 16:04:07 +01:00
Id = id;
2020-12-06 16:01:38 +01:00
SetEmail(email);
SetName(name);
SetSurname(surname);
SetLogin(login);
SetPassword(password);
2020-12-18 16:04:07 +01:00
CreatedAt = DateTime.UtcNow;
2020-12-06 16:01:38 +01:00
}
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;
}
}
}