public IEnumerable <AuditLogEntity> SearchAuditLogs(AuditLogSearchFilter searchFilter) { string selectAllValue = Constants.ApplicationStatus.All.ConvertToString(); DateTime dateTo = DateTime.Now; if (searchFilter.DateToValue.HasValue) { dateTo = searchFilter.DateToValue.Value.AddDays(1); } var query = from au in _context.TB_L_AUDIT_LOG.AsNoTracking() from us in _context.TB_R_USER.Where(o => o.USER_ID == au.CREATE_USER).DefaultIfEmpty() where !string.IsNullOrEmpty(au.MODULE) && !_ignoreActions.Contains(au.MODULE) && !string.IsNullOrEmpty(au.ACTION) && !_ignoreActions.Contains(au.ACTION) && (string.IsNullOrEmpty(searchFilter.FirstName) || (us.FIRST_NAME.ToUpper().Contains(searchFilter.FirstName.ToUpper()))) && (string.IsNullOrEmpty(searchFilter.LastName) || (us.LAST_NAME.ToUpper().Contains(searchFilter.LastName.ToUpper()))) && (string.IsNullOrEmpty(searchFilter.Module) || selectAllValue == searchFilter.Module || au.MODULE.ToUpper().Contains(searchFilter.Module.ToUpper())) && (string.IsNullOrEmpty(searchFilter.Action) || selectAllValue == searchFilter.Action || au.ACTION.ToUpper().Equals(searchFilter.Action.ToUpper())) && (searchFilter.Status == null || searchFilter.Status == Constants.ApplicationStatus.All || au.STATUS == searchFilter.Status) && (!searchFilter.DateFromValue.HasValue || au.CREATE_DATE >= searchFilter.DateFromValue.Value) && (!searchFilter.DateToValue.HasValue || au.CREATE_DATE <= dateTo) select new AuditLogEntity { AuditLogId = au.AUDIT_LOG_ID, CreatedDate = au.CREATE_DATE, IpAddress = au.IP_ADDRESS, Action = au.ACTION, Module = au.MODULE, Detail = au.DETAIL, Status = (LogStatus)au.STATUS, User = (us != null ? new UserEntity { Firstname = us.FIRST_NAME, Lastname = us.LAST_NAME, PositionCode = us.POSITION_CODE } : null) }; int startPageIndex = (searchFilter.PageNo - 1) * searchFilter.PageSize; searchFilter.TotalRecords = query.Count(); if (startPageIndex >= searchFilter.TotalRecords) { startPageIndex = 0; searchFilter.PageNo = 1; } query = SetAuditLogListSort(query, searchFilter); return(query.Skip(startPageIndex).Take(searchFilter.PageSize).ToList <AuditLogEntity>()); }
public ActionResult AuditLogList(AuditLogSearchFilter searchFilter) { Logger.Info(_logMsg.Clear().SetPrefixMsg("Search AuditLog").Add("Name", searchFilter.FirstName) .Add("DateFrom", searchFilter.DateFrom).Add("DateTo", searchFilter.DateTo).Add("Module", searchFilter.Module) .Add("Action", searchFilter.Action).Add("Status", searchFilter.Status)); try { #region "Validation" bool isValid = TryUpdateModel(searchFilter); if (!string.IsNullOrEmpty(searchFilter.DateFrom) && !searchFilter.DateFromValue.HasValue) { isValid = false; ModelState.AddModelError("txtFromDate", Resource.ValErr_InvalidDate); } else if (searchFilter.DateFromValue.HasValue) { if (searchFilter.DateFromValue.Value > DateTime.Now.Date) { isValid = false; ModelState.AddModelError("txtFromDate", Resource.ValErr_InvalidDate_MustLessThanToday); } } if (!string.IsNullOrEmpty(searchFilter.DateTo) && !searchFilter.DateToValue.HasValue) { isValid = false; ModelState.AddModelError("txtToDate", Resource.ValErr_InvalidDate); } else if (searchFilter.DateToValue.HasValue) { if (searchFilter.DateToValue.Value > DateTime.Now.Date) { isValid = false; ModelState.AddModelError("txtToDate", Resource.ValErr_InvalidDate_MustLessThanToday); } } if (searchFilter.DateFromValue.HasValue && searchFilter.DateToValue.HasValue && searchFilter.DateFromValue.Value > searchFilter.DateToValue.Value) { isValid = false; ModelState.AddModelError("dvDateRange", Resource.ValErr_InvalidDateRange); } #endregion if (isValid) { _commonFacade = new CommonFacade(); _auditlogFacade = new AuditLogFacade(); AuditLogViewModel auditlogVM = new AuditLogViewModel(); auditlogVM.SearchFilter = searchFilter; auditlogVM.AuditLogList = _auditlogFacade.SearchAuditLogs(searchFilter); ViewBag.PageSize = auditlogVM.SearchFilter.PageSize; ViewBag.PageSizeList = _commonFacade.GetPageSizeList(); return(PartialView("~/Views/AuditLog/_AuditLogList.cshtml", auditlogVM)); } return(Json(new { Valid = false, Error = string.Empty, Errors = GetModelValidationErrors() })); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("Search AuditLog").Add("Error Message", ex.Message).ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }
public IEnumerable <AuditLogEntity> SearchAuditLogs(AuditLogSearchFilter searchFilter) { _auditLogDataAccess = new AuditLogDataAccess(_context); return(_auditLogDataAccess.SearchAuditLogs(searchFilter)); }
private static IQueryable <AuditLogEntity> SetAuditLogListSort(IQueryable <AuditLogEntity> auditlogList, AuditLogSearchFilter searchFilter) { if (searchFilter.SortOrder.ToUpper(CultureInfo.InvariantCulture).Equals("ASC")) { switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture)) { case "CREATE DATE": return(auditlogList.OrderBy(ord => ord.CreatedDate)); case "CREATE USER": return(auditlogList.OrderBy(ord => ord.User.PositionCode).ThenBy(ord => ord.User.Firstname).ThenBy(ord => ord.User.Lastname)); case "IPADDRESS": return(auditlogList.OrderBy(ord => ord.IpAddress)); case "MODULE": return(auditlogList.OrderBy(ord => ord.Module)); case "ACTION": return(auditlogList.OrderBy(ord => ord.Action)); case "STATUS": return(auditlogList.OrderBy(ord => ord.Status)); case "DETAIL": return(auditlogList.OrderBy(ord => ord.Detail)); default: return(auditlogList.OrderBy(ord => ord.AuditLogId)); } } else { switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture)) { case "CREATE DATE": return(auditlogList.OrderByDescending(ord => ord.CreatedDate)); case "CREATE USER": return(auditlogList.OrderByDescending(ord => ord.User.PositionCode).ThenByDescending(ord => ord.User.Firstname).ThenByDescending(ord => ord.User.Lastname)); case "IPADDRESS": return(auditlogList.OrderByDescending(ord => ord.IpAddress)); case "MODULE": return(auditlogList.OrderByDescending(ord => ord.Module)); case "ACTION": return(auditlogList.OrderByDescending(ord => ord.Action)); case "STATUS": return(auditlogList.OrderByDescending(ord => ord.Status)); case "DETAIL": return(auditlogList.OrderByDescending(ord => ord.Detail)); default: return(auditlogList.OrderByDescending(ord => ord.AuditLogId)); } } }