You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

10 years ago
  1. using System;
  2. using System.ComponentModel;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. namespace Sevomin.Models
  6. {
  7. class AdViewModel
  8. {
  9. [Key]
  10. public long Id { get; set; }
  11. [DisplayName("عنوان")]
  12. [Required(ErrorMessage = "{0} را وارد کنید")]
  13. public string Title { get; set; }
  14. [Required(ErrorMessage = "{0} را وارد کنید")]
  15. [DisplayName("متن")]
  16. public string Description { get; set; }
  17. [Required(ErrorMessage = "{0} را وارد کنید")]
  18. [DisplayName("تعداد روز")]
  19. public int Duration { get; set; }
  20. [DisplayName("تعداد کلیک")]
  21. public long ClickCount { get; set; }
  22. [DisplayName("لینک")]
  23. [Required(ErrorMessage = "{0} را وارد کنید")]
  24. public string Link { get; set; }
  25. [DisplayName("تاریخ ساخته شدن")]
  26. public DateTime CreatedDate { get; set; }
  27. [DisplayName("فعال")]
  28. public bool Active { get; set; }
  29. [NotMapped]
  30. public bool Expired
  31. {
  32. get { return (CreatedDate.AddDays(Duration) < DateTime.Now); }
  33. }
  34. public AdViewModel(Ad ad)
  35. {
  36. Id = ad.Id;
  37. Duration = ad.Duration;
  38. Link = ad.Link;
  39. ClickCount = ad.ClickCount;
  40. CreatedDate = ad.CreatedDate;
  41. Title = ad.Title;
  42. Description = ad.Description;
  43. }
  44. }
  45. }