public async Task <IActionResult> Drawings(int id, int page = 1) { try { int take = 15; int skip = take * (page - 1); var drawingList = await _userService.GetPaginatedUserDrawingListAsync(id, skip, take); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = drawingList.Count, CurrentPage = page, ItemsPerPage = take }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } var user = await _userService.GetDetails(id); SetPageTitle(user); DrawingListViewModel viewModel = new DrawingListViewModel() { DrawingWinners = drawingList.Data, PaginateModel = paginateModel, Id = id, HouseholdCount = await _userService.FamilyMemberCountAsync(user.HouseholdHeadUserId ?? id), HeadOfHouseholdId = user.HouseholdHeadUserId, HasAccount = !string.IsNullOrWhiteSpace(user.Username) }; return(View(viewModel)); } catch (GraException gex) { ShowAlertWarning("Unable to view participant's drawings: ", gex); return(RedirectToAction("Index")); } }
public async Task <IActionResult> Index(string FilterBy, int page = 1) { int take = 15; int skip = take * (page - 1); bool archived = String.Equals(FilterBy, "Archived", StringComparison.OrdinalIgnoreCase); if (archived) { PageTitle = "Archived Drawings"; } var drawingList = await _drawingService.GetPaginatedDrawingListAsync(skip, take, archived); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = drawingList.Count, CurrentPage = page, ItemsPerPage = take }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } DrawingListViewModel viewModel = new DrawingListViewModel() { Drawings = drawingList.Data, PaginateModel = paginateModel, Archived = archived }; return(View(viewModel)); }
public async Task <IActionResult> Index(string search, int?systemId, int?branchId, bool?mine, int?programId, bool?archived, int page = 1) { var filter = new DrawingFilter(page); if (!string.IsNullOrWhiteSpace(search)) { filter.Search = search; } if (archived == true) { filter.Archived = true; PageTitle = "Archived Drawings"; } if (mine == true) { filter.UserIds = new List <int> { GetId(ClaimType.UserId) }; } else if (branchId.HasValue) { filter.BranchIds = new List <int> { branchId.Value }; } else if (systemId.HasValue) { filter.SystemIds = new List <int> { systemId.Value }; } if (programId.HasValue) { if (programId.Value > 0) { filter.ProgramIds = new List <int?> { programId.Value }; } else { filter.ProgramIds = new List <int?> { null }; } } var drawingList = await _drawingService.GetPaginatedDrawingListAsync(filter); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = drawingList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } var systemList = (await _siteService.GetSystemList()) .OrderByDescending(_ => _.Id == GetId(ClaimType.SystemId)).ThenBy(_ => _.Name); DrawingListViewModel viewModel = new DrawingListViewModel() { Drawings = drawingList.Data, PaginateModel = paginateModel, Archived = archived, Search = search, SystemId = systemId, BranchId = branchId, ProgramId = programId, Mine = mine, SystemList = systemList, ProgramList = await _siteService.GetProgramList() }; if (mine == true) { viewModel.BranchList = (await _siteService.GetBranches(GetId(ClaimType.SystemId))) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); viewModel.ActiveNav = "Mine"; } else if (branchId.HasValue) { var branch = await _siteService.GetBranchByIdAsync(branchId.Value); viewModel.BranchName = branch.Name; viewModel.SystemName = systemList .Where(_ => _.Id == branch.SystemId).SingleOrDefault().Name; viewModel.BranchList = (await _siteService.GetBranches(branch.SystemId)) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); viewModel.ActiveNav = "Branch"; } else if (systemId.HasValue) { viewModel.SystemName = systemList .Where(_ => _.Id == systemId.Value).SingleOrDefault().Name; viewModel.BranchList = (await _siteService.GetBranches(systemId.Value)) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); viewModel.ActiveNav = "System"; } else { viewModel.BranchList = (await _siteService.GetBranches(GetId(ClaimType.SystemId))) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); viewModel.ActiveNav = "All"; } if (programId.HasValue) { if (programId.Value > 0) { viewModel.ProgramName = (await _siteService.GetProgramByIdAsync(programId.Value)).Name; } else { viewModel.ProgramName = "Not Limited"; } } return(View(viewModel)); }