public async Task <IActionResult> EditBranch(BranchesListViewModel model) { if (model != null) { try { if (await _siteLookupService.IsSiteSettingSetAsync(GetCurrentSiteId(), SiteSettingKey.Events.GoogleMapsAPIKey)) { model.Branch.Geolocation = null; var newAddress = model.Branch.Address?.Trim(); var currentBranch = await _siteService.GetBranchByIdAsync(model.Branch.Id); if (string.IsNullOrWhiteSpace(currentBranch.Geolocation) || !string.Equals(currentBranch.Address, newAddress, StringComparison.OrdinalIgnoreCase)) { var result = await _spatialService .GetGeocodedAddressAsync(newAddress); if (result.Status == ServiceResultStatus.Success) { model.Branch.Geolocation = result.Data; } else if (result.Status == ServiceResultStatus.Warning) { ShowAlertWarning("Unable to set branch geolocation: ", result.Message); } else { ShowAlertDanger("Unable to set branch geolocation: ", result.Message); } } } await _siteService.UpdateBranchAsync(model.Branch); ShowAlertSuccess($"Branch '{model.Branch.Name}' updated"); } catch (GraException gex) { ShowAlertDanger("Unable to edit Branch: ", gex); } } return(RedirectToAction("Branches", new { search = model?.Search })); }
private async Task <IActionResult> ShowExitPageAsync(SiteStage siteStage, int?branchId = null) { string siteName = HttpContext.Items[ItemKey.SiteName]?.ToString(); PageTitle = _sharedLocalizer[Annotations.Title.SeeYouSoon, siteName]; var exitPageViewModel = new ExitPageViewModel(); try { var culture = _userContextProvider.GetCurrentCulture(); exitPageViewModel.Social = await _socialService.GetAsync(culture.Name); } catch (GraException ex) { _logger.LogInformation(ex, "Unable to populate social card for exit page: {ErrorMessage}", ex.Message); } if (branchId == null) { try { exitPageViewModel.Branch = await _userService.GetUsersBranch(GetActiveUserId()); } catch (GraException) { } } if (exitPageViewModel.Branch == null && branchId.HasValue) { try { exitPageViewModel.Branch = await _siteService.GetBranchByIdAsync(branchId.Value); } catch (GraException) { } } return(siteStage switch { SiteStage.BeforeRegistration => View(ViewTemplates.ExitBeforeRegistration, exitPageViewModel), SiteStage.RegistrationOpen => View(ViewTemplates.ExitRegistrationOpen, exitPageViewModel), SiteStage.ProgramEnded => View(ViewTemplates.ExitProgramEnded, exitPageViewModel), SiteStage.AccessClosed => View(ViewTemplates.ExitAccessClosed, exitPageViewModel), _ => View(ViewTemplates.ExitProgramOpen, exitPageViewModel), });
private async Task <IActionResult> ShowExitPageAsync(SiteStage siteStage, int?branchId = null) { string siteName = HttpContext.Items[ItemKey.SiteName]?.ToString(); PageTitle = _sharedLocalizer[Annotations.Title.SeeYouSoon, siteName]; ExitPageViewModel exitPageViewModel = null; try { exitPageViewModel = new ExitPageViewModel { Branch = branchId == null ? await _userService.GetUsersBranch(GetActiveUserId()) : await _siteService.GetBranchByIdAsync((int)branchId) }; } catch (GraException ex) { _logger.LogInformation(ex, "Attempt to show exit page failed for branch id {BranchId}: {Message}", branchId, ex.Message); } switch (siteStage) { case SiteStage.BeforeRegistration: return(View(ViewTemplates.ExitBeforeRegistration, exitPageViewModel)); case SiteStage.RegistrationOpen: return(View(ViewTemplates.ExitRegistrationOpen, exitPageViewModel)); case SiteStage.ProgramEnded: return(View(ViewTemplates.ExitProgramEnded, exitPageViewModel)); case SiteStage.AccessClosed: return(View(ViewTemplates.ExitAccessClosed, exitPageViewModel)); default: return(View(ViewTemplates.ExitProgramOpen, exitPageViewModel)); } }
private async Task <ChallengesListViewModel> GetChallengeList(string filterBy, string search, int page, int?filterId = null) { int take = 15; int skip = take * (page - 1); var challengeList = await _challengeService .MCGetPaginatedChallengeListAsync(skip, take, search, filterBy, filterId); foreach (var challenge in challengeList.Data) { if (!string.IsNullOrEmpty(challenge.BadgeFilename)) { challenge.BadgeFilename = _pathResolver.ResolveContentPath(challenge.BadgeFilename); } } PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = challengeList.Count, CurrentPage = page, ItemsPerPage = take }; var systemList = (await _siteService.GetSystemList()) .OrderByDescending(_ => _.Id == GetId(ClaimType.SystemId)).ThenBy(_ => _.Name); ChallengesListViewModel viewModel = new ChallengesListViewModel() { Challenges = challengeList.Data, PaginateModel = paginateModel, FilterBy = filterBy, FilterId = filterId, Search = search, CanAddChallenges = UserHasPermission(Permission.AddChallenges), CanDeleteChallenges = UserHasPermission(Permission.RemoveChallenges), CanEditChallenges = UserHasPermission(Permission.EditChallenges), SystemList = systemList }; if (!string.IsNullOrWhiteSpace(filterBy)) { if (filterBy.Equals("System", StringComparison.OrdinalIgnoreCase)) { var systemId = filterId ?? GetId(ClaimType.SystemId); viewModel.SystemName = systemList .Where(_ => _.Id == systemId).SingleOrDefault().Name; viewModel.BranchList = (await _siteService.GetBranches(systemId)) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); } else if (filterBy.Equals("Branch", StringComparison.OrdinalIgnoreCase)) { var branchId = filterId ?? GetId(ClaimType.BranchId); var branch = await _siteService.GetBranchByIdAsync(branchId); 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); } } if (viewModel.BranchList == null) { viewModel.BranchList = (await _siteService.GetBranches(GetId(ClaimType.SystemId))) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); } return(viewModel); }
public async Task <IActionResult> Index(int page = 1, string search = null, int?system = null, int?branch = null, int?location = null, int?program = null, string StartDate = null, string EndDate = null, bool CommunityExperiences = false) { ModelState.Clear(); EventFilter filter = new EventFilter(page) { Search = search, EventType = CommunityExperiences ? 1 : 0 }; // ignore location if branch has value if (branch.HasValue) { filter.BranchIds = new List <int>() { branch.Value }; } else if (system.HasValue) { filter.SystemIds = new List <int>() { system.Value }; } else if (location.HasValue) { filter.LocationIds = new List <int?>() { location.Value }; } if (program.HasValue) { filter.ProgramIds = new List <int?>() { program.Value }; } if (!String.Equals(StartDate, "False", StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrWhiteSpace(StartDate)) { DateTime startDate; if (DateTime.TryParse(StartDate, out startDate)) { filter.StartDate = startDate.Date; } } else { filter.StartDate = _dateTimeProvider.Now.Date; } } if (!string.IsNullOrWhiteSpace(EndDate)) { DateTime endDate; if (DateTime.TryParse(EndDate, out endDate)) { filter.EndDate = endDate.Date; } } var eventList = await _eventService.GetPaginatedListAsync(filter); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = eventList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } EventsListViewModel viewModel = new EventsListViewModel() { Events = eventList.Data, PaginateModel = paginateModel, Search = search, StartDate = filter.StartDate, EndDate = filter.EndDate, ProgramId = program, SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"), LocationList = new SelectList((await _eventService.GetLocations()), "Id", "Name"), ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name"), CommunityExperiences = CommunityExperiences }; if (branch.HasValue) { var selectedBranch = await _siteService.GetBranchByIdAsync(branch.Value); viewModel.SystemId = selectedBranch.SystemId; viewModel.BranchList = new SelectList( (await _siteService.GetBranches(selectedBranch.SystemId)), "Id", "Name", branch.Value); } else if (system.HasValue) { viewModel.SystemId = system; viewModel.BranchList = new SelectList( (await _siteService.GetBranches(system.Value)), "Id", "Name"); } else { viewModel.BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"); } if (location.HasValue && !branch.HasValue) { viewModel.LocationId = location.Value; viewModel.UseLocation = true; } return(View("Index", viewModel)); }
public async Task<IActionResult> Index(int page = 1, string search = null, int? branch = null, int? location = null, int? program = null, string StartDate = null, string EndDate = null) { EventFilter filter = new EventFilter(page) { Search = search, }; // ignore location if branch has value if (branch.HasValue) { filter.BranchIds = new List<int>() { branch.Value }; } else if (location.HasValue) { filter.LocationIds = new List<int?>() { location.Value }; } if (program.HasValue) { filter.ProgramIds = new List<int?>() { program.Value }; } if (!string.IsNullOrWhiteSpace(StartDate)) { filter.StartDate = DateTime.Parse(StartDate).Date; } if (!string.IsNullOrWhiteSpace(EndDate)) { filter.EndDate = DateTime.Parse(EndDate).Date; } var eventList = await _eventService.GetPaginatedListAsync(filter); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = eventList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return RedirectToRoute( new { page = paginateModel.LastPage ?? 1 }); } EventsListViewModel viewModel = new EventsListViewModel() { Events = eventList.Data, PaginateModel = paginateModel, Search = search, ProgramId = program, SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"), LocationList = new SelectList((await _eventService.GetLocations()), "Id", "Name"), ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name") }; if (branch.HasValue) { var selectedBranch = await _siteService.GetBranchByIdAsync(branch.Value); viewModel.SystemId = selectedBranch.SystemId; viewModel.BranchList = new SelectList( (await _siteService.GetBranches(selectedBranch.SystemId)), "Id", "Name", branch.Value); } else { viewModel.BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"); } if (location.HasValue && !branch.HasValue) { viewModel.LocationId = location.Value; viewModel.UseLocation = true; } return View(viewModel); }
public async Task <IActionResult> Index(int page = 1, string sort = null, string search = null, string near = null, int?system = null, int?branch = null, int?location = null, int?program = null, string StartDate = null, string EndDate = null, bool Favorites = false, string Visited = null, EventType eventType = EventType.Event, HttpStatusCode httpStatus = HttpStatusCode.OK) { var site = await GetCurrentSiteAsync(); if (!string.IsNullOrEmpty(site.ExternalEventListUrl)) { return(new RedirectResult(site.ExternalEventListUrl)); } ModelState.Clear(); var filter = new EventFilter(page) { Search = search, EventType = (int)eventType }; var nearSearchEnabled = await _siteLookupService .IsSiteSettingSetAsync(site.Id, SiteSettingKey.Events.GoogleMapsAPIKey); if (!string.IsNullOrWhiteSpace(sort) && Enum.IsDefined(typeof(SortEventsBy), sort)) { filter.SortBy = (SortEventsBy)Enum.Parse(typeof(SortEventsBy), sort); } else { if (nearSearchEnabled && !string.IsNullOrWhiteSpace(near)) { filter.SortBy = SortEventsBy.Distance; } } if (AuthUser.Identity.IsAuthenticated) { filter.Favorites = Favorites; if (string.IsNullOrWhiteSpace(Visited) || string.Equals(Visited, VisitedNo, StringComparison.OrdinalIgnoreCase)) { filter.IsAttended = false; } else if (string.Equals(Visited, VisitedYes, StringComparison.OrdinalIgnoreCase)) { filter.IsAttended = true; } } if (nearSearchEnabled) { if (!string.IsNullOrWhiteSpace(near)) { var geocodeResult = await _spatialService.GetGeocodedAddressAsync(near); if (geocodeResult.Status == ServiceResultStatus.Success) { filter.SpatialDistanceHeaderId = await _spatialService .GetSpatialDistanceIdForGeolocationAsync(geocodeResult.Data); } else { ShowAlertWarning("Not able to find that location."); return(RedirectToAction(nameof(Index))); } } } else { // ignore location if branch has value if (branch.HasValue) { filter.BranchIds = new List <int>() { branch.Value }; } else if (system.HasValue) { filter.SystemIds = new List <int>() { system.Value }; } else if (location.HasValue) { filter.LocationIds = new List <int?>() { location.Value }; } } if (program.HasValue) { filter.ProgramIds = new List <int?>() { program.Value }; } if (!string.Equals(StartDate, "False", StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrWhiteSpace(StartDate)) { if (DateTime.TryParse(StartDate, out var startDate)) { filter.StartDate = startDate.Date; } } else { filter.StartDate = _dateTimeProvider.Now.Date; } } if (!string.IsNullOrWhiteSpace(EndDate) && DateTime.TryParse(EndDate, out var endDate)) { filter.EndDate = endDate.Date; } var eventList = await _eventService.GetPaginatedListAsync(filter); var paginateModel = new PaginateViewModel { ItemCount = eventList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.PastMaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } var viewModel = new EventsListViewModel { IsAuthenticated = AuthUser.Identity.IsAuthenticated, Events = eventList.Data.ToList(), PaginateModel = paginateModel, Sort = filter.SortBy.ToString(), Search = search, StartDate = filter.StartDate, EndDate = filter.EndDate, Favorites = Favorites, IsLoggedIn = AuthUser.Identity.IsAuthenticated, ProgramId = program, ProgramList = new SelectList(await _siteService.GetProgramList(), "Id", "Name"), EventType = eventType, ShowNearSearch = nearSearchEnabled, }; if (nearSearchEnabled) { viewModel.Near = near?.Trim(); if (HttpContext.User.Identity.IsAuthenticated) { var user = await _userService.GetDetails(GetActiveUserId()); if (!string.IsNullOrWhiteSpace(user.PostalCode)) { viewModel.UserZipCode = user.PostalCode; } } } else { viewModel.SystemList = new SelectList( await _siteService.GetSystemList(), "Id", "Name"); viewModel.LocationList = new SelectList( await _eventService.GetLocations(), "Id", "Name"); if (branch.HasValue) { var selectedBranch = await _siteService.GetBranchByIdAsync(branch.Value); viewModel.SystemId = selectedBranch.SystemId; viewModel.BranchList = new SelectList( await _siteService.GetBranches(selectedBranch.SystemId), "Id", "Name", branch.Value); } else if (system.HasValue) { viewModel.SystemId = system; viewModel.BranchList = new SelectList( await _siteService.GetBranches(system.Value), "Id", "Name"); } else { viewModel.BranchList = new SelectList(await _siteService.GetAllBranches(), "Id", "Name"); } if (location.HasValue && !branch.HasValue) { viewModel.LocationId = location.Value; viewModel.UseLocation = true; } } var(descriptionTextSet, communityExperienceDescription) = await _siteLookupService .GetSiteSettingStringAsync(site.Id, SiteSettingKey.Events.CommunityExperienceDescription); if (descriptionTextSet) { viewModel.CommunityExperienceDescription = communityExperienceDescription; } if (eventType == EventType.StreamingEvent) { viewModel.Viewed = Visited; } else { viewModel.Visited = Visited; } if (httpStatus != HttpStatusCode.OK) { Response.StatusCode = (int)httpStatus; } return(View(nameof(Index), 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)); }
private async Task <EventsListViewModel> GetEventList(int?eventType, string search, int?systemId, int?branchId, bool?mine, int?programId, int page = 1) { EventFilter filter = new EventFilter(page) { EventType = eventType }; if (!string.IsNullOrWhiteSpace(search)) { filter.Search = search; } 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 eventList = await _eventService.GetPaginatedListAsync(filter, true); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = eventList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; var systemList = (await _siteService.GetSystemList()) .OrderByDescending(_ => _.Id == GetId(ClaimType.SystemId)).ThenBy(_ => _.Name); EventsListViewModel viewModel = new EventsListViewModel() { Events = eventList.Data, PaginateModel = paginateModel, Search = search, SystemId = systemId, BranchId = branchId, ProgramId = programId, Mine = mine, SystemList = systemList, ProgramList = await _siteService.GetProgramList(), CanManageLocations = UserHasPermission(Permission.ManageLocations), RequireSecretCode = await GetSiteSettingBoolAsync( SiteSettingKey.Events.RequireBadge) }; 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(viewModel); }
public async Task <IActionResult> Index(string search, int?systemId, int?branchId, bool?mine, int?programId, int page = 1) { var filter = new TriggerFilter(page); if (!string.IsNullOrWhiteSpace(search)) { filter.Search = search; } 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 triggerList = await _triggerService.GetPaginatedListAsync(filter); var paginateModel = new PaginateViewModel { ItemCount = triggerList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.PastMaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } foreach (var trigger in triggerList.Data) { trigger.AwardBadgeFilename = _pathResolver.ResolveContentPath(trigger.AwardBadgeFilename); var graEvent = (await _eventService.GetRelatedEventsForTriggerAsync(trigger.Id)) .FirstOrDefault(); if (graEvent != null) { trigger.RelatedEventId = graEvent.Id; trigger.RelatedEventName = graEvent.Name; } } var systemList = (await _siteService.GetSystemList()) .OrderByDescending(_ => _.Id == GetId(ClaimType.SystemId)).ThenBy(_ => _.Name); var viewModel = new TriggersListViewModel { Triggers = triggerList.Data, PaginateModel = paginateModel, 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 .SingleOrDefault(_ => _.Id == branch.SystemId)?.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 .SingleOrDefault(_ => _.Id == systemId.Value)?.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)); }
private async Task <ChallengesListViewModel> GetChallengeList(string Search, int?Program, int?System, int?Branch, bool?Mine, int page = 1, bool pending = false) { BaseFilter filter = new BaseFilter(page); if (!string.IsNullOrWhiteSpace(Search)) { filter.Search = Search; } if (System.HasValue) { filter.SystemIds = new List <int>() { System.Value }; } if (Branch.HasValue) { filter.BranchIds = new List <int>() { Branch.Value }; } if (Program.HasValue) { if (Program.Value == 0) { filter.ProgramIds = new List <int?>() { null }; } else { filter.ProgramIds = new List <int?>() { Program.Value }; } } if (Mine == true) { filter.UserIds = new List <int>() { GetId(ClaimType.UserId) }; } if (pending) { filter.IsActive = false; } var challengeList = await _challengeService .MCGetPaginatedChallengeListAsync(filter); foreach (var challenge in challengeList.Data) { if (!string.IsNullOrEmpty(challenge.BadgeFilename)) { challenge.BadgeFilename = _pathResolver.ResolveContentPath(challenge.BadgeFilename); } } PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = challengeList.Count, CurrentPage = (filter.Skip.Value / filter.Take.Value) + 1, ItemsPerPage = filter.Take.Value }; var systemList = (await _siteService.GetSystemList()) .OrderByDescending(_ => _.Id == GetId(ClaimType.SystemId)).ThenBy(_ => _.Name); ChallengesListViewModel viewModel = new ChallengesListViewModel() { Challenges = challengeList.Data, PaginateModel = paginateModel, Search = filter.Search, System = System, Branch = Branch, Program = Program, Mine = Mine, CanAddChallenges = UserHasPermission(Permission.AddChallenges), CanDeleteChallenges = UserHasPermission(Permission.RemoveChallenges), CanEditChallenges = UserHasPermission(Permission.EditChallenges), 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"; if (pending && !UserHasPermission(Permission.ActivateAllChallenges)) { viewModel.SystemName = systemList .Where(_ => _.Id == GetId(ClaimType.SystemId)).SingleOrDefault().Name; } } else if (Branch.HasValue) { var branch = await _siteService.GetBranchByIdAsync(viewModel.Branch.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 (System.HasValue) { viewModel.SystemName = systemList .Where(_ => _.Id == viewModel.System.Value).SingleOrDefault().Name; viewModel.BranchList = (await _siteService.GetBranches(viewModel.System.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 (Program.HasValue) { if (Program.Value > 0) { viewModel.ProgramName = (await _siteService.GetProgramByIdAsync(Program.Value)).Name; } else { viewModel.ProgramName = "Not Limited"; } } return(viewModel); }