49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using EnVisage.Code;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
public class RoleModel : IBaseModel<AspNetRole>
|
|
{
|
|
public Guid Id { get; set; }
|
|
[Required]
|
|
public string Name { get; set; }
|
|
public int AspNetUsersCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// Casts a <see cref="AspNetRole"/> obect to the object of type <see cref="RoleModel"/>.
|
|
/// </summary>
|
|
/// <param name="obj">A <see cref="AspNetRole"/> object.</param>
|
|
/// <returns>A <see cref="RoleModel"/> object filled with data from db.</returns>
|
|
public static explicit operator RoleModel(AspNetRole obj)
|
|
{
|
|
if (obj == null)
|
|
return null;
|
|
var model = new RoleModel
|
|
{
|
|
Id = Guid.Parse(obj.Id),
|
|
Name = obj.Name,
|
|
AspNetUsersCount = obj.AspNetUsers.Count
|
|
};
|
|
model.TrimStringProperties();
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies data from model to DAL object.
|
|
/// </summary>
|
|
/// <param name="dbObj">A target DAL object.</param>
|
|
public void CopyTo(AspNetRole dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
if (string.IsNullOrEmpty(dbObj.Id) && !Guid.Empty.Equals(Id))
|
|
dbObj.Id = Id.ToString();
|
|
dbObj.Name = Name;
|
|
}
|
|
}
|
|
} |