API
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.

BaseEntity.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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
  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. #endregion
  22. #region Methods
  23. public virtual void UpdateModified(string modifiedBy)
  24. {
  25. Modified = DateTime.Now;
  26. if (string.IsNullOrEmpty(modifiedBy))
  27. {
  28. ModifiedBy = modifiedBy;
  29. }
  30. }
  31. public void Validate()
  32. {
  33. Valid = ValidateObject();
  34. }
  35. public virtual ValidateEntity ValidateObject()
  36. {
  37. ValidateEntity v = new ValidateEntity();
  38. return v;
  39. }
  40. public object this[string propertyName]
  41. {
  42. get { return GetType().GetProperty(propertyName).GetValue(this, null); }
  43. set { GetType().GetProperty(propertyName).SetValue(this, value, null); }
  44. }
  45. public string[] GetAllProperties()
  46. {
  47. if (this == null) return new string[] { };
  48. Type t = GetType();
  49. PropertyInfo[] props = t.GetProperties();
  50. List<string> propNames = new List<string>();
  51. foreach (PropertyInfo prp in props)
  52. {
  53. propNames.Add(prp.Name);
  54. }
  55. return propNames.ToArray();
  56. }
  57. #endregion Methods
  58. }
  59. }