using PortalAccountsContracts.BindingModels; using PortalAccountsContracts.ViewModels; using PortalAccountsDataModels.Models; using System.ComponentModel.DataAnnotations; namespace PortalAccountsDatabaseImplement.Models { public class Account : IAccountModel { public int Id { get; private set; } [Required] public string Login { get; set; } = string.Empty; public string? AvatarPath { get; set; } [Required] public int InterestId { get; set; } public string? Email { get; set; } public virtual Interest Interest { get; set; } public static Account? Create(AccountBindingModel? model) { if (model == null) { return null; } return new Account() { Id = model.Id, Login = model.Login, AvatarPath = model.AvatarPath, InterestId = model.InterestId, Email = model.Email }; } public void Update(AccountBindingModel? model) { if (model == null) { return; } Login = model.Login; AvatarPath = model.AvatarPath; InterestId = model.InterestId; Email = model.Email; } public AccountViewModel GetViewModel => new() { Id = Id, Login = Login, AvatarPath = AvatarPath, InterestId = InterestId, InterestName = Interest.Name ?? string.Empty, Email = Email }; } }