I have a DB that all of its entities have some log fields for Create/Modify/Delete and I have to take Current User Id in all of my CRUD Actions and set these fields for security purpose ....
this is an example of my Entities :
//log properties
public byte RecordStatus { get; set; }
public string RecordStatusDescription { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedDateTime { get; set; }
public string CreatorIPAddress { get; set; }
public string ModifiedBy { get; set; }
public DateTime ModifiedDateTime { get; set; }
public string ModifierIPAddress { get; set; }
public string RemovedBy { get; set; }
public string RemovedDateTime { get; set; }
public string RemoverIPAddress { get; set; }
public bool IsRemoved { get; set; }
I'm using Repository and I want to add something like this to my IRepository interface :
public interface IBaseRepository<TEntity> where TEntity : class
{
void Createdby(string UserId , string userIP);
void ModifiedBy(string UserId , string userIP);
void RemovedBy(string UserID , string userIP);
}
so how can I implement this in my Repository and then use it in my actions !?
I can set this fields in traditional way but I want to have more cleaner Actions ...
Alright so you have to make a clear IRepository and make it as simple as possible like this(since you want this Generic):
IRepository:
And Create One Generic Repository like below:
Good thing about EntityBase is since all of your properties have an id, you can easily go like this:
And then implement this to your Models :
Advantage of using this simple Repository is you can easily do anything with it e.g. :