49 lines
1.1 KiB
C#
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
|
|
};
|
|
}
|
|
}
|
|
|