CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Role.cs

56 lines
1.3 KiB
C#
Raw Normal View History

2024-04-29 01:55:20 +04:00
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Role : IRoleModel
{
public int ID { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public static Role? Create(RoleBindingModel? model)
{
if (model == null)
{
return null;
}
return new Role()
{
ID = model.ID,
Name = model.Name
};
}
public static Role? Create(RoleViewModel model)
{
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
};
}
}