using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Web.Mvc; namespace EnVisage.Models { public class RateModel : IBaseModel { #region enums and subclasses public enum RateType { Global = 0, Derived = 1 } #endregion public Guid Id { get; set; } public Guid? ParentId { get; set; } public Guid ExpenditureCategoryId { get; set; } public RateType Type { get; set; } [Required] [Display(Name = "Rate")] [DisplayFormat(DataFormatString = "{0:0.00}", ApplyFormatInEditMode = true)] [Range(typeof(Decimal), "0.01", "9999999.99", ErrorMessage = "{0} must be a decimal/number between {1} and {2}.")] public decimal Rate1 { get; set; } [Display(Name = "Start Date")] [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)] public DateTime StartDate { get; set; } [Display(Name = "End Date")] [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)] [DateGreaterThanOrEqualAttribute("StartDate", "Rate End Date should not be less than Start Date")] public DateTime EndDate { get; set; } public Guid? DerivedObjectId { get; set; } public int FreezeRate { get; set; } //public virtual ExpenditureCategory ExpenditureCategory { get; set; } /// /// Casts a obect to the object of type . /// /// A object. /// A object filled with data from db. public static explicit operator RateModel(Rate obj) { if (obj == null) return null; var model = new RateModel { Id = obj.Id, ParentId = obj.ParentId, ExpenditureCategoryId = obj.ExpenditureCategoryId, Type = (RateType)obj.Type, Rate1 = obj.Rate1, StartDate = obj.StartDate, EndDate = obj.EndDate, DerivedObjectId = obj.DerivedId, FreezeRate = obj.FreezeRate, }; return model; } /// /// Copies data from model to DAL object. /// /// A target DAL object. public void CopyTo(Rate dbObj) { if (dbObj == null) throw new ArgumentNullException(); dbObj.ParentId = ParentId; dbObj.ExpenditureCategoryId = ExpenditureCategoryId; dbObj.Type = (short)Type; dbObj.Rate1 = Rate1; dbObj.StartDate = StartDate; dbObj.EndDate = EndDate; dbObj.DerivedId = DerivedObjectId; dbObj.FreezeRate = FreezeRate; } } }