123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Reflection;
-
- namespace ProRestaurant.Models
- {
- public class BaseObject
- {
- #region Properties
- [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- [Key]
- public int Id { get; set; }
- public DateTime Created { get; set; } = DateTime.Now;
- public DateTime Modified { get; set; } = DateTime.Now;
- public string ModifiedBy { get; set; }
- public bool IsDeleted { get; set; } = false;
- #endregion
-
- #region Methods
- public virtual void UpdateModified(string modifiedBy)
- {
- Modified = DateTime.Now;
- if (string.IsNullOrEmpty(modifiedBy))
- {
- ModifiedBy = modifiedBy;
- }
- }
-
- public object this[string propertyName]
- {
- get { return GetType().GetProperty(propertyName).GetValue(this, null); }
- set { GetType().GetProperty(propertyName).SetValue(this, value, null); }
- }
-
- public string[] GetAllProperties()
- {
- if (this == null) return new string[] { };
- Type t = GetType();
- PropertyInfo[] props = t.GetProperties();
- List<string> propNames = new List<string>();
- foreach (PropertyInfo prp in props)
- {
- propNames.Add(prp.Name);
- }
- return propNames.ToArray();
- }
- #endregion
- }
- }
|