Exemple #1
0
        protected void LogAudit(ModelType modelType, dynamic model, string filePath, string requestType, long customerId)
        {
            if (!IoC.Resolve <ISettings>().AuditEnabled)
            {
                return;
            }
            try
            {
                if (modelType == ModelType.Edit)
                {
                    _modelId = _auditLogFilterHelper.GetEditModelIdValue(model);
                }

                _activityType = modelType == ModelType.Edit && _modelId > 0
                    ? Type.Updated
                    : (modelType == ModelType.Edit ? Type.Created : Type.Retrieved);


                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(filePath, requestType, model, _activityType.ToString());
                if (customerId > 0)
                {
                    logModel.CustomerId = customerId;
                }
                _auditLogFilterHelper.LogModel(modelType, logModel, model);
            }
            catch (Exception ex)
            {
                var logger = IoC.Resolve <ILogManager>().GetLogger("BaseWebService");
                logger.Error("Error in BaseWebService LogAudit", ex);
            }
        }
Exemple #2
0
        protected void LogAudit(ModelType modelType, dynamic model, long customerId)
        {
            if (!IoC.Resolve <ISettings>().AuditEnabled)
            {
                return;
            }
            try
            {
                if (modelType == ModelType.Edit)
                {
                    _modelId = _auditLogFilterHelper.GetEditModelIdValue(model);
                }

                _activityType = modelType == ModelType.Edit && _modelId > 0
                    ? Type.Updated
                    : (modelType == ModelType.Edit ? Type.Created : Type.Retrieved);

                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(this.Request, model, _activityType.ToString());

                if (logModel != null)
                {
                    if (customerId > 0)
                    {
                        logModel.CustomerId = customerId;
                    }
                    _auditLogFilterHelper.LogModel(modelType, logModel, model);
                }
                else
                {
                    var logger = IoC.Resolve <ILogManager>().GetLogger("BasePage");
                    logger.Info("Session is null while Saving Audit Data");
                }
            }
            catch (Exception ex)
            {
                var logger = IoC.Resolve <ILogManager>().GetLogger("BasePage");
                logger.Error("Error in BasePage LogAudit");
                logger.Error("Message: " + ex.Message);
                logger.Error("Stack Trace: " + ex.StackTrace);
            }
        }
Exemple #3
0
        private void ParseRequestOnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpRequestBase request = filterContext.HttpContext.Request;

            //if ((request.RequestType.ToUpper() == "POST" || request.RequestType.ToUpper() == "DELETE") && (actionName.Contains("remove") || actionName.Contains("delete")))
            //{
            //    _deletedEntity = _activityLogDeleteService.GetEntity(filterContext);
            //    return;
            //}

            if (filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(true).Any(m => m.GetType() == typeof(IgnoreAuditAttribute)))
            {
                return;
            }

            if (filterContext.ActionDescriptor.GetCustomAttributes(true).Any(m => m.GetType() == typeof(IgnoreAuditAttribute)))
            {
                return;
            }

            if (request.RequestType.ToUpper() != "POST" || !filterContext.ActionParameters.Keys.Any(x => x.ToLower().Contains("model")) || !_settings.AuditEnabled)
            {
                return;
            }

            if (_sessionContext.UserSession == null)
            {
                return;
            }

            var model = filterContext.ActionParameters.FirstOrDefault(x => x.Key.ToLower().Contains("model")).Value;

            if (model == null)
            {
                return;
            }

            var modelName = (string)model.GetType().Name;

            var modelType  = ReflectionHelper.GetModelType(model);
            var modelState = filterContext.Controller.ViewData.ModelState;

            if (modelType == ModelType.Edit)
            {
                _modelId = _auditLogFilterHelper.GetEditModelIdValue(model);
            }

            _activityType = modelType == ModelType.Edit && _modelId > 0
                ? Type.Updated
                : (modelType == ModelType.Edit ? Type.Created : Type.Retrieved);

            var logModel = _auditLogFilterHelper.GetActivityLogEditModel(request, model, _activityType.ToString());

            var customer = filterContext.ActionParameters.FirstOrDefault(x => x.Key.ToLower().Equals("customerid"));

            int customerId = Convert.ToInt32(customer.Value);

            if (logModel != null)
            {
                logModel.CustomerId = customerId;

                bool isLogged = ExceptionClassLogging(modelName, model, logModel);

                if (!isLogged && modelState.IsValid && (_activityType == Type.Created || _activityType == Type.Updated))
                {
                    _activityLogService.LogEditModel(logModel, model);
                }
            }
            else
            {
                _logger.Info("Session is null while Saving Audit Data");
            }
        }
Exemple #4
0
        private void ParseRequestOnActionExecuting(HttpActionContext actionContext)
        {
            var request = HttpContext.Current.Request;

            //var actionName = actionContext.ActionDescriptor.ActionName.ToLower();
            //if ((request.RequestType.ToUpper() == "POST" || request.RequestType.ToUpper() == "DELETE") && (actionName.Contains("remove") || actionName.Contains("delete")))
            //{
            //    _deletedEntity = _activityLogDeleteService.GetEntity(actionContext);
            //    return;
            //}

            if (actionContext.ActionDescriptor.ControllerDescriptor.ControllerType.GetCustomAttributes(true).Any(m => m.GetType() == typeof(IgnoreAuditAttribute)))
            {
                return;
            }

            if (actionContext.ActionDescriptor.ReturnType.GetCustomAttributes(true).Any(m => m.GetType() == typeof(IgnoreAuditAttribute)))
            {
                return;
            }

            if (request.RequestType.ToUpper() != "POST" || !actionContext.ActionArguments.Any(x => x.Key.ToLower().Contains("model") || x.Key.ToLower().Contains("filter")) || !_settings.AuditEnabled)
            {
                return;
            }

            if (_sessionContext.UserSession == null)
            {
                return;
            }

            //var model = actionContext.ActionArguments["model"];
            var model = actionContext.ActionArguments.First(x => x.Key.ToLower().Contains("model")).Value;

            if (model == null)
            {
                model = actionContext.ActionArguments.First(x => x.Key.ToLower().Contains("filter")).Value;

                if (model == null)
                {
                    return;
                }
            }

            var modelType  = ReflectionHelper.GetModelType(model);
            var modelState = actionContext.ModelState;

            if (modelType == ModelType.Edit)
            {
                _modelId = _auditLogFilterHelper.GetEditModelIdValue(model);
            }
            _activityType = modelType == ModelType.Edit && _modelId > 0
               ? Type.Updated
               : (modelType == ModelType.Edit ? Type.Created : Type.Retrieved);

            var logModel = _auditLogFilterHelper.GetActivityLogEditModel(request, model, _activityType.ToString());

            if (logModel != null)
            {
                if (modelState.IsValid && (_activityType == Type.Created || _activityType == Type.Updated))
                {
                    _activityLogService.LogEditModel(logModel, model, true);
                }
            }
            else
            {
                _logger.Info("Session is null while Saving Audit Data");
            }
        }