using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using EnVisage.Code; using System.Web.Mvc; namespace EnVisage.Models { public class RoleModel : IBaseModel { //ENV-612 START public Guid Id { get { return _Id; } set { this._Id = value; if (value == Guid.Empty) this._isNew = true; else this._isNew = false; } } //public Guid Id { get; set;} public bool isNew { get { return _isNew; } } private bool _isNew = false; private Guid _Id = Guid.Empty; //ENV-746 END [Required] [Remote("IsUnique", "Role", HttpMethod = "POST", AdditionalFields="Id", ErrorMessage = "The role name entered is already in use please enter a different role name")] 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; } /// /// Once a model is created a the generated guid needs to be /// applied to this model so that future saves of the projects and category’s /// have correct model ID. /// /// A target DAL object. public void setIDForNewModel(Guid g) { this._Id = g; this._isNew = true; } /// /// 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; } } }