'Advice how to do audit with some entity fields
i am looking for another way that how can i set those fields through database instead of doing in service layer all the time one by one :) I wonder if i can make all those by using custom attribute or is there any extension that i can handle those stuff ?
public interface IBaseEntity
{
DateTime CreatedDate { get; set; }
string CreatedIpAddress { get; set; }
string CreatedMachineName { get; set; }
DateTime? UpdatedDate { get; set; }
string UpdatedIpAddress { get; set; }
string UpdatedMachineName { get; set; }
DateTime? DeletedDate { get; set; }
string DeletedIpAddress { get; set; }
string DeletedMachineName { get; set; }
Status Status { get; set; }
}
as shown below i set those fields manually like that;
public void Delete(int id)
{
Category category = _categoryRepo.GetDefault(x => x.Id == id);
category.DeletedDate = DateTime.Now;
category.DeletedMachineName = Environment.MachineName;
category.DeletedIpAddress = CatchIP.IpAddress;
category.Status = Status.Passive;
_categoryRepo.Delete(category);
}
appreciate all the advice and information since i've been just writing for 4 months :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|