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 { public Guid Id { get; set; } [Required] public string Name { get; set; } public int AspNetUsersCount { get; set; } /// /// Casts a obect to the object of type . /// /// A object. /// A object filled with data from db. 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; } /// /// Copies data from model to DAL object. /// /// A target DAL object. 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; } } }