using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using EnVisage.Code; namespace EnVisage.Models { public class StatusModel : IBaseModel { public Guid Id { get; set; } [Required] [MaxLength(100)] [Display(Name = "Status")] public string Name { get; set; } [Required] [MaxLength(8)] public string Color { get; set; } [Display(Name = "Number of Projects")] public int ProjectsCount { get; set; } [Display(Name="100% probability")] public string Probability100 { get; set; } /// /// Casts a obect to the object of type . /// /// A object. /// A object filled with data from db. public static explicit operator StatusModel(Status obj) { if (obj == null) return null; var model = new StatusModel { Id = obj.Id, Name = obj.Name, Color = obj.Color, ProjectsCount = obj.Projects.Count, Probability100 = obj.Probability100 ? "Yes" : "No" }; model.TrimStringProperties(); return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(Status dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.Name = Name; dbObj.Color = Color.Replace("#", ""); dbObj.Probability100 = Probability100 == "Yes"; } } }