PIbd-21_Pyatakov_KM_Markov_.../UniversityDataBaseImplemet/Models/Role.cs

59 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityModels.Models;
namespace UniversityDataBaseImplemet.Models
{
public class Role : IRoleModel
{
[Required]
public string Name { get; set; } = string.Empty;
public int Id { get; set; }
[ForeignKey("RoleId")]
public virtual List<User> Users { get; set; } = new();
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
};
}
}