Esempio n. 1
0
        protected override void Dispose(bool disposing)
        {
            if (lastContext != null && !lastContext.IsJsonResult())
            {
                ControllerActionDescriptor controllerActionDescriptor = lastContext.ActionDescriptor as ControllerActionDescriptor;
                if (controllerActionDescriptor != null)
                {
                    var disableAuditOnController = controllerActionDescriptor
                                                   .ControllerTypeInfo
                                                   .CustomAttributes
                                                   .Where(a => a.AttributeType == typeof(DisableAuditAttribute))
                                                   .Any();

                    var disableAuditOnAction = controllerActionDescriptor
                                               .MethodInfo
                                               .CustomAttributes
                                               .Where(a => a.AttributeType == typeof(DisableAuditAttribute))
                                               .Any();

                    if (!disableAuditOnController && !disableAuditOnAction)
                    {
                        var auditLog = new Infrastructure.Data.Models.Audit.AuditLog()
                        {
                            CourtId  = userContext.CourtId,
                            UserId   = userContext.UserId,
                            Method   = Request?.Method,
                            ClientIP = lastClientIP
                        };
                        var _context = CurrentContext;
                        if (_context.IsRead && _context.LastController == this.ControllerName)
                        {
                            auditLog.Operation  = _context.Info.Operation;
                            auditLog.ObjectType = _context.Info.ObjectType;
                            auditLog.BaseObject = _context.Info.BaseObject;
                            auditLog.ObjectInfo = _context.Info.ObjectInfo;
                        }
                        else
                        {
                            //ако няма контекст - се взема само title на страницата - зададен е в layout.cshtml
                            var pageTitle = TempData["PageTitle"];
                            auditLog.Operation  = AuditConstants.Operations.View;
                            auditLog.BaseObject = (string)pageTitle;
                        }
                        //if (Request.Headers.TryGetValue("X-Forwarded-For", out var currentIp))
                        //{
                        //    string ip = currentIp;
                        //    auditLog.ClientIP = ip;
                        //}
                        auditLog.RequestUrl = lastContext.HttpContext.Request.Path;
                        var auditService = (IAuditLogService)HttpContext.RequestServices.GetService(typeof(IAuditLogService));
                        auditService.SaveLog(auditLog);
                    }
                }
            }

            base.Dispose(disposing);
        }
Esempio n. 2
0
        protected void AddAuditInfo(string operation, string baseInfo, string addInfo = null)
        {
            var auditService = (IAuditLogService)HttpContext.RequestServices.GetService(typeof(IAuditLogService));
            var auditLog     = new Infrastructure.Data.Models.Audit.AuditLog()
            {
                CourtId    = userContext.CourtId,
                Operation  = operation,
                BaseObject = baseInfo,
                ObjectInfo = addInfo,
                UserId     = userContext.UserId
            };

            auditService.SaveLog(auditLog);
        }