public IActionResult Index(string searchTerm, int page = 1) { page = Math.Max(1, page); var allLogs = this.logService.GetAll(); if (!string.IsNullOrWhiteSpace(searchTerm)) { allLogs = allLogs.Where(u => u.UserEmail.ToLower().Contains(searchTerm.ToLower())); } var totalPages = (int)(Math.Ceiling(allLogs.Count() / (double)WebConstants.LogsListPageSize)); page = Math.Min(page, Math.Max(1, totalPages)); var logsToShow = allLogs .Skip((page - 1) * WebConstants.LogsListPageSize) .Take(WebConstants.LogsListPageSize) .ToList(); var model = new UserActivityLogListViewModel { SearchTerm = searchTerm, Logs = new PaginatedList <UserActivityLogConciseServiceModel>(logsToShow, page, totalPages) }; return(View(model)); }
public IActionResult Index(string searchTerm, string criteria, int page = 1) { page = Math.Max(1, page); var allLogs = this.logService.GetAll(); Enum.TryParse(criteria, out LogSearchCriteria logCriteria); if (!string.IsNullOrWhiteSpace(searchTerm)) { switch (logCriteria) { case LogSearchCriteria.Email: allLogs = allLogs.Where(l => l.UserEmail.ToLower().Contains(searchTerm.ToLower())); break; case LogSearchCriteria.Controller: allLogs = allLogs.Where(l => l.ControllerName.ToLower().Contains(searchTerm.ToLower())); break; case LogSearchCriteria.Action: allLogs = allLogs.Where(l => l.ActionName.ToLower().Contains(searchTerm.ToLower())); break; case LogSearchCriteria.Http_Method: allLogs = allLogs.Where(l => l.HttpMethod.ToLower().Contains(searchTerm.ToLower())); break; default: break; } } var totalPages = (int)(Math.Ceiling(allLogs.Count() / (double)LogsListPageSize)); page = Math.Min(page, Math.Max(1, totalPages)); var logsToShow = allLogs .Skip((page - 1) * LogsListPageSize) .Take(LogsListPageSize) .ToList(); var model = new UserActivityLogListViewModel { SearchTerm = searchTerm, AllSearchCriterias = Enum.GetNames(typeof(LogSearchCriteria)).Select(c => new SelectListItem(c, c)), SearchCriteria = criteria, Logs = new PaginatedList <UserActivityLogConciseServiceModel>(logsToShow, page, totalPages) }; return(View(model)); }