53 lines
1.2 KiB
C#
53 lines
1.2 KiB
C#
using BlogContracts.BindingModels;
|
|
using BlogContracts.ViewModels;
|
|
using BlogDataModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BlogDatabase.Models
|
|
{
|
|
public class Role : IRoleModel
|
|
{
|
|
[Required]
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
public int Id { get; private set; }
|
|
|
|
[ForeignKey("UserId")]
|
|
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 void Update(RoleBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
}
|
|
public RoleViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
};
|
|
}
|
|
}
|