public override void OnActionExecuting(ActionExecutingContext context) { var controller = context.ActionDescriptor as ControllerActionDescriptor; int.TryParse(context.HttpContext?.User?.FindFirst("Id")?.Value, out int id); var actionName = controller?.ActionName; var method = context.HttpContext?.Request?.Method; var audit = new Models.Audit() { ActionName = controller?.ActionName, ControllerName = controller?.ControllerName, IpAddress = context.HttpContext?.Connection?.RemoteIpAddress?.ToString(), AccessDate = DateTime.Now, PageAccessed = context.HttpContext?.Request?.GetDisplayUrl(), Method = method, KorisnikId = id != 0 ? id : (int?)null, LoggedInAt = actionName == "Login" && method == "POST" ? DateTime.Now : (DateTime?)null, LoggedOutAt = actionName == "Logout" ? DateTime.Now : (DateTime?)null, ResponseStatusCode = context.HttpContext?.Response?.StatusCode ?? 0, IsLoggedIn = id != 0 ? true : false }; _auditRepo.Add(audit); _auditRepo.SaveChanges(); base.OnActionExecuting(context); }
public async Task <bool> Log <T>(Enums.AuditLevel level, string userName, string key, string description, T oldValue, T newValue, params string[] propertyIgnore) { var changes = await getDifferenceObjectService.Get(oldValue, newValue, propertyIgnore); var model = new Models.Audit() { Level = level, Messages = changes, UserName = userName, Key = key, Description = description }; await insertAuditService.Insert(model); return(true); }
public async Task Add(Models.Audit audit) { await _audits.InsertOneAsync(audit); }
public async Task <Models.Audit> Insert(Models.Audit audit) { await repository.Add(audit); return(audit); }