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

49 lines
1.1 KiB
C#

using PortalAccountsContracts.BindingModels;
using PortalAccountsContracts.ViewModels;
using PortalAccountsDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PortalAccountsDatabaseImplement.Models
{
public class Role : IRoleModel
{
public int Id { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
[ForeignKey("RoleId")]
public virtual List<Account> Accounts { get; set; } = new();
public static Role? Create(RoleBindingModel model)
{
if (model == null)
{
return null;
}
return new Role()
{
Id = model.Id,
Name = model.Name
};
}
public void Update(RoleBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public RoleViewModel GetViewModel => new()
{
Id = Id,
Name = Name
};
}
}