Пример #1
0
        void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
        {
            // TODO: Add your acction filter's tasks here
            // Log Action Filter Call

            var actionLogService = (IActionLogService)DependencyResolver.Current.GetService(typeof(IActionLogService));
            string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            string actionName = filterContext.ActionDescriptor.ActionName;
            string ipAddress = filterContext.HttpContext.Request.UserHostAddress;
            DateTime timestamp = filterContext.HttpContext.Timestamp;
            int Id = 0;
            if (!String.IsNullOrEmpty(filterContext.HttpContext.Request.Form["Id"]))
                Id = Convert.ToInt32(filterContext.HttpContext.Request.Form["Id"]);
            var currentUser = SessionContext.getUser();
            string status = string.Empty;
            string userName = currentUser != null ? currentUser.Email : "Khách";
            // Trường hợp thêm mới hoặc cập nhật
            if (actionName.Contains("CreateOrUpdate"))
            {
                status = "tạo mới bản ghi";
                if (Id > 0)
                {
                    status = "cập nhật bản ghi";
                }
            }
            // Trường hợp cập nhật trạng thái active/ not active
            else if (actionName.Contains("Published"))
            {
                bool published = Convert.ToBoolean(filterContext.HttpContext.Request.Params["published"]);
                status = String.Format("cập nhật trạng thái ({0})", published ? "bỏ kích hoạt" : "kích hoạt");
            }
            else if (actionName.Contains("Active"))
            {
                bool active = Convert.ToBoolean(filterContext.HttpContext.Request.Params["active"]);
                status = String.Format("cập nhật trạng thái ({0})", active ? "bỏ kích hoạt" : "kích hoạt");
            }
            // Trường hợp xóa bản ghi
            else if (actionName.Contains("Delete"))
            {
                status = "xóa bản ghi";
            }
            else if (actionName.Contains("LogIn"))
            {
                status = "đăng nhập";
            }
            string message = String.Format("{0} đã {1} trong {2} vào lúc {3}", userName, status, getTextControllerName(controllerName), timestamp.ToString("dd/MM/yyyy hh:mm:ss tt"));
            string note = String.Format("{0} -> {1} -> {2}", controllerName, actionName, Id);
            ActionLog log = new ActionLog()
            {
                Controller = controllerName,
                Action = actionName,
                IP = ipAddress,
                Date = timestamp,
                Message = message,
                Note = note
            };
            actionLogService.Insert(log);
            this.OnActionExecuted(filterContext);
        }
Пример #2
0
 public void Delete(ActionLog ActionLog)
 {
     _actionLogRepository.Delete(ActionLog);
 }
Пример #3
0
 public void Insert(ActionLog ActionLog)
 {
     _actionLogRepository.Insert(ActionLog);
 }