API
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using System.Reflection;
  6. using UnivateProperties_API.Containers;
  7. namespace UnivateProperties_API.Model
  8. {
  9. public class BaseEntity : IDisplay
  10. {
  11. #region Properties
  12. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  13. [Key]
  14. public int Id { get; set; }
  15. public DateTime Created { get; set; } = DateTime.Now;
  16. public DateTime Modified { get; set; } = DateTime.Now;
  17. public string ModifiedBy { get; set; }
  18. [NotMapped]
  19. public ValidateEntity Valid { get; set; }
  20. public bool IsDeleted { get; set; } = false;
  21. [NotMapped]
  22. public virtual string Display { get { return ToString(); } }
  23. #endregion
  24. #region Methods
  25. public virtual void UpdateModified(string modifiedBy)
  26. {
  27. Modified = DateTime.Now;
  28. if (string.IsNullOrEmpty(modifiedBy))
  29. {
  30. ModifiedBy = modifiedBy;
  31. }
  32. }
  33. public void Validate()
  34. {
  35. Valid = ValidateObject();
  36. }
  37. public virtual ValidateEntity ValidateObject()
  38. {
  39. ValidateEntity v = new ValidateEntity();
  40. return v;
  41. }
  42. public object this[string propertyName]
  43. {
  44. get { return GetType().GetProperty(propertyName).GetValue(this, null); }
  45. set { GetType().GetProperty(propertyName).SetValue(this, value, null); }
  46. }
  47. public string[] GetAllProperties()
  48. {
  49. if (this == null) return new string[] { };
  50. Type t = GetType();
  51. PropertyInfo[] props = t.GetProperties();
  52. List<string> propNames = new List<string>();
  53. foreach (PropertyInfo prp in props)
  54. {
  55. propNames.Add(prp.Name);
  56. }
  57. return propNames.ToArray();
  58. }
  59. #endregion Methods
  60. }
  61. }