Example #1
0
        public async void AsyncLogModel(ModelType modelType, ActivityLogEditModel logModel, dynamic model, bool fromAPI = false)
        {
            if (modelType == ModelType.List)
            {
                await _activityLogService.LogListModel(logModel, model, fromAPI);
            }
            else if (modelType == ModelType.View)
            {
                await _activityLogService.LogViewModel(logModel, model, fromAPI);
            }
            else if (modelType == ModelType.Edit)
            {
                var modelId = GetEditModelIdValue(logModel);

                if (modelId > 0)
                {
                    await _activityLogService.LogEditModel(logModel, model, fromAPI);
                }
                else
                {
                    await _activityLogService.LogViewModel(logModel, model, fromAPI);
                }
            }
            else
            {
                await _activityLogService.LogEditModel(logModel, model, fromAPI);
            }
        }
Example #2
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");
            }
        }
Example #3
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");
            }
        }