using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Sevomin.Models { class AdViewModel { [Key] public long Id { get; set; } [DisplayName("عنوان")] [Required(ErrorMessage = "{0} را وارد کنید")] public string Title { get; set; } [Required(ErrorMessage = "{0} را وارد کنید")] [DisplayName("متن")] public string Description { get; set; } [Required(ErrorMessage = "{0} را وارد کنید")] [DisplayName("تعداد روز")] public int Duration { get; set; } [DisplayName("تعداد کلیک")] public long ClickCount { get; set; } [DisplayName("لینک")] [Required(ErrorMessage = "{0} را وارد کنید")] public string Link { get; set; } [DisplayName("تاریخ ساخته شدن")] public DateTime CreatedDate { get; set; } [DisplayName("فعال")] public bool Active { get; set; } [NotMapped] public bool Expired { get { return (CreatedDate.AddDays(Duration) < DateTime.Now); } } public AdViewModel(Ad ad) { Id = ad.Id; Duration = ad.Duration; Link = ad.Link; ClickCount = ad.ClickCount; CreatedDate = ad.CreatedDate; Title = ad.Title; Description = ad.Description; } } }