Example #1
0
        protected void LogRelatedModel(dynamic filter, dynamic model, long customerId)
        {
            if (!IoC.Resolve <ISettings>().AuditEnabled)
            {
                return;
            }
            try
            {
                _activityType = Type.Retrieved;

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

                if (logModel != null)
                {
                    if (customerId > 0)
                    {
                        logModel.CustomerId = customerId;
                    }
                    _activityLogService.LogRelatedModel(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("BaseUserControl");
                logger.Error("Error in BaseUserControl LogRelatedModel", ex);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        protected void LogFilterListPairAudit(dynamic filter, dynamic model)
        {
            if (!IoC.Resolve <ISettings>().AuditEnabled)
            {
                return;
            }
            try
            {
                _activityType = Type.Retrieved;

                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(this.Request, model, _activityType.ToString());
                if (logModel != null)
                {
                    _activityLogService.LogFilterModelPair(logModel, filter, 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 LogFilterListPairAudit");
                logger.Error("Message: " + ex.Message);
                logger.Error("Stack Trace: " + ex.StackTrace);
            }
        }
Example #4
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);
            }
        }
Example #5
0
        protected void LogFilterListPairAudit(ModelType modelType, dynamic filter, dynamic model, string filePath, string requestType)
        {
            if (!IoC.Resolve <ISettings>().AuditEnabled)
            {
                return;
            }
            try
            {
                _activityType = modelType == ModelType.Edit
                        ? Type.Updated
                        : (modelType == ModelType.Edit ? Type.Created : Type.Retrieved);

                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(filePath, requestType, model, _activityType.ToString());
                _activityLogService.LogFilterModelPair(logModel, filter, model);
            }
            catch (Exception ex)
            {
                var logger = IoC.Resolve <ILogManager>().GetLogger("BaseWebService");
                logger.Error("Error in BaseWebService LogFilterListPairAudit", ex);
            }
        }
Example #6
0
        protected void LogRelatedModel(dynamic filter, dynamic model, string filePath, string requestType, long customerId)
        {
            if (!IoC.Resolve <ISettings>().AuditEnabled)
            {
                return;
            }
            try
            {
                _activityType = Type.Retrieved;

                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(filePath, requestType, model, _activityType.ToString());
                if (customerId > 0)
                {
                    logModel.CustomerId = customerId;
                }
                _activityLogService.LogRelatedModel(logModel, model);
            }
            catch (Exception ex)
            {
                var logger = IoC.Resolve <ILogManager>().GetLogger("BaseWebService");
                logger.Error("Error in BaseWebService LogRelatedModel", ex);
            }
        }
Example #7
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 #8
0
        private void ParseRequestOnActionExecuted(ActionExecutedContext filterContext)
        {
            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 (!(filterContext.Result is ViewResultBase || filterContext.Result is JsonResult || filterContext.Result is RedirectResult || filterContext.Result is ContentResult))
            {
                return;
            }

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

            dynamic model = null;

            if ((filterContext.Result is ViewResultBase))
            {
                model = ((ViewResultBase)filterContext.Result).Model;
            }
            if ((filterContext.Result is JsonResult))
            {
                model = ((JsonResult)filterContext.Result).Data;
            }
            if ((filterContext.Result is RedirectResult))
            {
                model = ((RedirectResult)filterContext.Result);
            }
            if ((filterContext.Result is ContentResult))
            {
                model = ((ContentResult)filterContext.Result);
            }

            if (model == null)
            {
                return;
            }

            _activityType = Type.Retrieved;

            var customerId = 0;
            var customer   = filterContext.ActionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterName.ToLower().Equals("customerid"));

            if (customer != null)
            {
                customerId = Convert.ToInt32(filterContext.Controller.ValueProvider.GetValue(customer.ParameterName).AttemptedValue);
            }

            HttpRequestBase request = filterContext.HttpContext.Request;

            if (_settings.AuditEnabled)
            {
                if (request.RequestType.ToUpper() == "GET")
                {
                    var logModel = _auditLogFilterHelper.GetActivityLogEditModel(request, model, _activityType.ToString());

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

                        var modelType = ReflectionHelper.GetModelType(model);

                        modelType = GetModelTypeForExceptions(model, modelType);

                        _auditLogFilterHelper.AsyncLogModel(modelType, logModel, model);
                    }
                    else
                    {
                        _logger.Info("Session is null while Saving Audit Data");
                    }
                }
                else if ((request.RequestType.ToUpper() == "POST" || request.RequestType.ToUpper() == "DELETE") &&
                         (filterContext.ActionDescriptor.ActionName.ToLower().Contains("remove") ||
                          filterContext.ActionDescriptor.ActionName.ToLower().Contains("delete")))
                {
                    //if (_activityLogDeleteService.IsDeleted(filterContext))
                    //{
                    //    var logModel = CreateModel(request);

                    //    logModel.CustomerId = customerId;

                    //    _activityLogService.LogDeleteActivity(logModel, _deletedEntity);
                    //}
                }
                else if (filterContext.ActionDescriptor.GetCustomAttributes(true).Any(m => m.GetType() == typeof(MustAuditAttribute)))
                {
                    var logModel = _auditLogFilterHelper.GetActivityLogEditModel(request, model, _activityType.ToString());

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

                        var modelType = ReflectionHelper.GetModelType(model);

                        _auditLogFilterHelper.AsyncLogModel(modelType, logModel, model);
                    }
                    else
                    {
                        _logger.Info("Session is null while Saving Audit Data");
                    }
                }
            }
        }
Example #9
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");
            }
        }
Example #10
0
        private void ParseRequestOnActionExecuted(HttpActionExecutedContext actionContext)
        {
            var request = HttpContext.Current.Request;

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

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

            if (!_settings.AuditEnabled)
            {
                return;
            }

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

            var responseModel = actionContext.Response.Content as ObjectContent;

            if (responseModel == null)
            {
                return;
            }

            var model = responseModel.Value; //holding the returned value

            if (model == null)
            {
                return;
            }

            _activityType = Type.Retrieved;

            if (request.RequestType.ToUpper() == "GET")
            {
                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(request, model, _activityType.ToString());

                var modelType = ReflectionHelper.GetModelType(model);
                if (logModel != null)
                {
                    _auditLogFilterHelper.AsyncLogModel(modelType, logModel, model, true);
                }
                else
                {
                    _logger.Info("Session is null while Saving Audit Data");
                }
            }
            //else if ((request.RequestType.ToUpper() == "POST" || request.RequestType.ToUpper() == "DELETE") &&
            //         (actionContext.ActionContext.ActionDescriptor.ActionName.ToLower() == "remove" ||
            //          actionContext.ActionContext.ActionDescriptor.ActionName.ToLower() == "delete"))
            //{

            //    if (!_activityLogDeleteService.IsDeleted(actionContext)) return;

            //    var logModel = new ActivityLogEditModel
            //    {
            //        Action = Type.Deleted.ToString(),
            //        UrlAccessed = request.FilePath ?? string.Empty,
            //        ModelFullName = _deletedEntity != null ? _deletedEntity.GetType().FullName : string.Empty,
            //        ModelName = _deletedEntity != null ? _deletedEntity.GetType().Name : string.Empty,
            //        RequestType = request.RequestType,
            //        Timestamp = DateTime.UtcNow,
            //        UserLogId =
            //            _sessionContext != null && _sessionContext.UserSession != null
            //                ? _sessionContext.UserSession.GetUserLog()
            //                : 0,
            //        AccessById = _sessionContext.UserSession.UserId
            //    };
            //    _activityLogService.LogDeleteActivity(logModel, _deletedEntity);
            //}
            else if (
                actionContext.ActionContext.ActionDescriptor.ReturnType.GetCustomAttributes(true)
                .Any(m => m.GetType() == typeof(MustAuditAttribute)))
            {
                var logModel = _auditLogFilterHelper.GetActivityLogEditModel(request, model, _activityType.ToString());

                var modelType = ReflectionHelper.GetModelType(model);

                if (logModel != null)
                {
                    _auditLogFilterHelper.AsyncLogModel(modelType, logModel, model, true);
                }
                else
                {
                    _logger.Info("Session is null while Saving Audit Data");
                }
            }
        }