Files
nashel-backend/src/Modules/Identity/Domain/Aggregates/Account.cs
Халимов Рустам 1e72d006c4 Страница профиля
2026-02-13 14:24:01 +03:00

62 lines
1.5 KiB
C#

using Nashel.BuildingBlocks.Domain;
using Nashel.Modules.Identity.Domain.Enums;
using Nashel.Modules.Identity.Domain.Events;
namespace Nashel.Modules.Identity.Domain.Aggregates;
public class Account : AggregateRoot<Guid>
{
public string Phone { get; private set; }
public string PasswordHash { get; private set; }
public List<Role> Roles { get; private set; } = new();
public UserProfile Profile { get; private set; } = default!;
// Конструктор для EF Core
private Account() { }
private Account(Guid id, string phone, string passwordHash)
{
Id = id;
Phone = phone;
PasswordHash = passwordHash;
Roles.Add(Role.User);
AddDomainEvent(new AccountCreatedEvent(Id));
}
public static Account Create(string phone, string passwordHash)
{
return new Account(Guid.NewGuid(), phone, passwordHash);
}
public void SetProfile(UserProfile profile)
{
Profile = profile;
}
public void ChangePhone(string newPhone)
{
Phone = newPhone;
}
public void BecomePerformer()
{
if (!Roles.Contains(Role.Candidate) && !Roles.Contains(Role.Master))
{
Roles.Add(Role.Candidate);
}
}
public void PromoteToMaster()
{
if (Roles.Contains(Role.Candidate))
{
Roles.Remove(Role.Candidate);
}
if (!Roles.Contains(Role.Master))
{
Roles.Add(Role.Master);
}
}
}