public void Insert(AuditView model) { using (var rep = new AuditRepository()) { rep.Insert(ConvertToAudit(model)); } }
private static Audit ConvertToAudit(AuditView modelView) { var dev = new Audit { AuditID = modelView.AuditID, UserName = modelView.UserName, Event = modelView.Event, TimeAccessed = modelView.TimeAccessed, }; return dev; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { //Stores the Request in an Accessible object var request = filterContext.HttpContext.Request; //Generate an audit AuditView audit = new AuditView() { AuditID = Guid.NewGuid(), Event = request.RawUrl, TimeAccessed = DateTime.UtcNow, UserName = (request.IsAuthenticated) ? filterContext.HttpContext.User.Identity.Name : "Anonymous", }; //Stores the Audit in the Database _auditRecords.Insert(audit); base.OnActionExecuting(filterContext); }