PIbd-31_Rodionov.I.A._COP_28/COP/PortalAccountsDatabaseImplement/Models/Account.cs
2024-10-22 19:42:03 +04:00

63 lines
1.6 KiB
C#

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? Warnings { get; set; }
[Required]
public int RoleId { get; set; }
public double? Rating { get; set; }
public virtual Role Role { get; set; }
public static Account? Create(AccountBindingModel? model)
{
if (model == null)
{
return null;
}
return new Account()
{
Id = model.Id,
Login = model.Login,
Warnings = model.Warnings,
RoleId = model.RoleId,
Rating = model.Rating
};
}
public void Update(AccountBindingModel? model)
{
if (model == null)
{
return;
}
Login = model.Login;
Warnings = model.Warnings;
RoleId = model.RoleId;
Rating = model.Rating;
}
public AccountViewModel GetViewModel => new()
{
Id = Id,
Login = Login,
Warnings = Warnings,
RoleId = RoleId,
RoleName = Role.Name ?? string.Empty,
Rating = Rating
};
}
}