using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using EnVisage.Code; using System.Linq; namespace EnVisage.Models { public class StrategicGoalModel : IBaseModel { public Guid Id { get; set; } [Required] [MaxLength(100)] [Display(Name = "Goal")] public string Name { get; set; } [Display(Name = "Description")] public string Description { get; set; } [Display(Name = "Number of Projects")] public int NbrProjects { get; set; } [Required] [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)] [Display(Name = "Start Date")] public DateTime? StartDate { get; set; } [Required] [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)] [Display(Name = "End Date")] public DateTime? EndDate { get; set; } [Display(Name = "Color")] public string Color { get; set; } public List Companies { get; set; } [UIHint("MultipleSelect")] [Display(Name = "Companies")] public List CompanyId { get; set; } public StrategicGoalModel() { Companies = new List(); } /// /// Casts a obect to the object of type . /// /// A object. /// A object filled with data from db. public static explicit operator StrategicGoalModel(StrategicGoal obj) { if (obj == null) return null; var model = new StrategicGoalModel { Id = obj.Id, Name = obj.Name, Description = obj.Description, StartDate = obj.StartDate.Value, EndDate = obj.EndDate.Value, Color = obj.Color, Companies = obj.StrategicGoal2Company.Select(x => new Company(){ Id = x.Company.Id, Name = x.Company.Name }).ToList() }; model.TrimStringProperties(); return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(StrategicGoal dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.Id = Id; dbObj.Name = Name; dbObj.Description = Description; dbObj.StartDate = StartDate; dbObj.EndDate = EndDate; dbObj.Color = Color; } } }