PIAPS_CW/DatabaseImplement/Models/Role.cs

47 lines
929 B
C#
Raw Permalink Normal View History

2024-06-04 21:16:50 +04:00
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Role : IRole
{
public Guid Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public RoleBindingModel GetBindingModel() => new()
{
Id = Id,
Name = Name,
};
public static Role ToRoleFromView(RoleViewModel model) => new()
{
Id = model.Id,
Name = model.Name,
};
public static Role ToRoleFromBinding(RoleBindingModel model) => new()
{
Id = model.Id,
Name = model.Name,
};
public void Update(RoleBindingModel model)
{
if (model is null)
{
throw new ArgumentNullException("Update role: bindinng model is null");
}
Name = model.Name;
}
}
}