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

108 lines
2.8 KiB
C#
Raw Permalink 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))
{
2021-01-09 11:55:07 +01:00
throw new Exception("Email nie może być pusty.");
2020-12-06 16:01:38 +01:00
}
if (Email == email)
{
return;
}
Email = email;
UpdatedAt = DateTime.UtcNow;
}
public void SetName(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
2021-01-09 11:55:07 +01:00
throw new Exception("Imię nie może być puste.");
2020-12-06 16:01:38 +01:00
}
if (Name == name)
{
return;
}
Name = name;
UpdatedAt = DateTime.UtcNow;
}
public void SetSurname(string surname)
{
if (string.IsNullOrWhiteSpace(surname))
{
2021-01-09 11:55:07 +01:00
throw new Exception("Nazwisko nie może być puste.");
2020-12-06 16:01:38 +01:00
}
if (Surname == surname)
{
return;
}
Surname = surname;
UpdatedAt = DateTime.UtcNow;
}
public void SetLogin(string login)
{
if (string.IsNullOrWhiteSpace(login))
{
2021-01-09 11:55:07 +01:00
throw new Exception("Login nie może być pusty.");
2020-12-06 16:01:38 +01:00
}
if (Login == login)
{
return;
}
Login = login;
UpdatedAt = DateTime.UtcNow;
}
public void SetPassword(string password)
{
if (string.IsNullOrWhiteSpace(password))
{
2021-01-09 11:55:07 +01:00
throw new Exception("Hasło nie może być puste.");
2020-12-06 16:01:38 +01:00
}
if (Password == password)
{
return;
}
Password = password;
UpdatedAt = DateTime.UtcNow;
}
}
}