public async Task <IActionResult> Create(int?id) { PageTitle = "Create Event"; var branchList = await _siteService.GetBranches(GetId(ClaimType.SystemId)); var locationList = await _eventService.GetLocations(); var programList = await _siteService.GetProgramList(); EventsDetailViewModel viewModel = new EventsDetailViewModel() { CanManageLocations = UserHasPermission(Permission.ManageLocations), BranchList = new SelectList(branchList, "Id", "Name"), LocationList = new SelectList(locationList, "Id", "Name"), ProgramList = new SelectList(programList, "Id", "Name") }; if (id.HasValue) { var graEvent = await _eventService.GetDetails(id.Value); if (!graEvent.ParentEventId.HasValue) { graEvent.ParentEventId = graEvent.Id; } viewModel.Event = graEvent; } return(View(viewModel)); }
public async Task <IActionResult> Index() { User user = await _userService.GetDetails(GetActiveUserId()); int householdCount = await _userService .FamilyMemberCountAsync(user.HouseholdHeadUserId ?? user.Id); var branchList = await _siteService.GetBranches(user.SystemId); var systemList = await _siteService.GetSystemList(); var programList = await _siteService.GetProgramList(); var userProgram = programList.Where(_ => _.Id == user.ProgramId).SingleOrDefault(); var programViewObject = _mapper.Map <List <ProgramViewModel> >(programList); ProfileDetailViewModel viewModel = new ProfileDetailViewModel() { User = user, HouseholdCount = householdCount, HasAccount = !string.IsNullOrWhiteSpace(user.Username), RequirePostalCode = (await GetCurrentSiteAsync()).RequirePostalCode, ShowAge = userProgram.AskAge, ShowSchool = userProgram.AskSchool, HasSchoolId = user.SchoolId.HasValue, ProgramJson = Newtonsoft.Json.JsonConvert.SerializeObject(programViewObject), BranchList = new SelectList(branchList.ToList(), "Id", "Name"), SystemList = new SelectList(systemList.ToList(), "Id", "Name"), ProgramList = new SelectList(programList.ToList(), "Id", "Name") }; var districtList = await _schoolService.GetDistrictsAsync(); if (user.SchoolId.HasValue) { var schoolDetails = await _schoolService.GetSchoolDetailsAsync(user.SchoolId.Value); var typeList = await _schoolService.GetTypesAsync(schoolDetails.SchoolDisctrictId); viewModel.SchoolDistrictList = new SelectList(districtList.ToList(), "Id", "Name", schoolDetails.SchoolDisctrictId); viewModel.SchoolTypeList = new SelectList(typeList.ToList(), "Id", "Name", schoolDetails.SchoolTypeId); viewModel.SchoolList = new SelectList(schoolDetails.Schools.ToList(), "Id", "Name"); } else { viewModel.SchoolDistrictList = new SelectList(districtList.ToList(), "Id", "Name"); } return(View(viewModel)); }
public async Task <IActionResult> CriteriaCreate() { PageTitle = "Drawing Criteria"; var brancList = await _siteService.GetBranches(1); CriterionDetailViewModel viewModel = new CriterionDetailViewModel() { BranchList = new SelectList(brancList.ToList(), "Id", "Name") }; return(View(viewModel)); }
public async Task <JsonResult> GetBranches(int?systemId, int?branchId, bool listAll = false, bool prioritize = false, bool includeSystemName = false) { var branchList = new List <Branch>(); if (systemId.HasValue) { branchList = (await _siteService.GetBranches(systemId.Value)).OrderBy(_ => _.Name) .ToList(); } else if (listAll) { branchList = (await _siteService.GetAllBranches(includeSystemName)) .OrderBy(_ => _.Name) .ToList(); } if (prioritize) { branchList = branchList.OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ToList(); } return(Json(new SelectList(branchList, "Id", "Name", branchId))); }
public async Task <IActionResult> CriteriaCreate(CriterionDetailViewModel model, string Drawing) { if (ModelState.IsValid) { if (model.ReadABook) { model.Criterion.PointTranslationId = 1; model.Criterion.ActivityAmount = 1; } var criterion = await _drawingService.AddCriterionAsync(model.Criterion); AlertSuccess = ($"Criteria <strong>{criterion.Name}</strong> created"); if (string.IsNullOrWhiteSpace(Drawing)) { return(RedirectToAction("CriteriaDetail", new { id = criterion.Id })); } else { return(RedirectToAction("New", new { id = criterion.Id })); } } else { PageTitle = "Drawing Criteria"; model.SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"); if (model.Criterion.SystemId.HasValue) { model.BranchList = new SelectList( (await _siteService.GetBranches(model.Criterion.SystemId.Value)), "Id", "Name"); } else { model.BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"); } model.ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name"); return(View(model)); } }
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 authCode = null; var useAuthCode = TempData.ContainsKey(EnteredAuthCode); if (useAuthCode) { authCode = (string)TempData[EnteredAuthCode]; } var site = await GetCurrentSiteAsync(); if (!site.SinglePageSignUp) { return(RedirectToAction(nameof(Step1))); } var siteStage = GetSiteStage(); if (!useAuthCode) { if (siteStage == SiteStage.BeforeRegistration) { if (site.RegistrationOpens.HasValue) { AlertInfo = _sharedLocalizer[Annotations.Info.YouCanJoinOn, site.Name, site.RegistrationOpens.Value.ToString("d")]; } else { AlertInfo = _sharedLocalizer[Annotations.Info.RegistrationNotOpenYet, site.Name]; } return(RedirectToAction(nameof(HomeController.Index), HomeController.Name)); } else if (siteStage >= SiteStage.ProgramEnded) { AlertInfo = _sharedLocalizer[Annotations.Info.ProgramEnded, site.Name]; return(RedirectToAction(nameof(HomeController.Index), HomeController.Name)); } } PageTitle = _sharedLocalizer[Annotations.Title.JoinNow, site.Name]; var systemList = await _siteService.GetSystemList(); var programList = await _siteService.GetProgramList(); var programViewObject = _mapper.Map <List <ProgramSettingsViewModel> >(programList); var viewModel = new SinglePageViewModel { RequirePostalCode = site.RequirePostalCode, ProgramJson = JsonConvert.SerializeObject(programViewObject), SystemList = NameIdSelectList(systemList.ToList()), ProgramList = NameIdSelectList(programList.ToList()), SchoolList = NameIdSelectList(await _schoolService.GetSchoolsAsync()) }; var askIfFirstTime = await GetSiteSettingBoolAsync(SiteSettingKey.Users.AskIfFirstTime); if (askIfFirstTime) { viewModel.AskFirstTime = EmptyNoYes(); } var(askEmailSubscription, askEmailSubscriptionText) = await GetSiteSettingStringAsync( SiteSettingKey.Users.AskEmailSubPermission); if (askEmailSubscription) { viewModel.AskEmailSubscription = EmptyNoYes(); viewModel.AskEmailSubscriptionText = askEmailSubscriptionText; } var(askActivityGoal, defaultDailyGoal) = await GetSiteSettingIntAsync( SiteSettingKey.Users.DefaultDailyPersonalGoal); if (askActivityGoal) { viewModel.DailyPersonalGoal = defaultDailyGoal; var pointTranslation = programList.First().PointTranslation; viewModel.TranslationDescriptionPastTense = pointTranslation.TranslationDescriptionPastTense.Replace("{0}", "").Trim(); viewModel.ActivityDescriptionPlural = pointTranslation.ActivityDescriptionPlural; } if (systemList.Count() == 1) { var systemId = systemList.Single().Id; var branchList = await _siteService.GetBranches(systemId); if (branchList.Count() > 1) { branchList = branchList.Prepend(new Branch() { Id = -1 }); } else { viewModel.BranchId = branchList.SingleOrDefault()?.Id; } viewModel.BranchList = NameIdSelectList(branchList.ToList()); viewModel.SystemId = systemId; } if (programList.Count() == 1) { var programId = programList.Single().Id; var program = await _siteService.GetProgramByIdAsync(programId); viewModel.ProgramId = programId; viewModel.ShowAge = program.AskAge; viewModel.ShowSchool = program.AskSchool; } if (useAuthCode) { viewModel.AuthorizationCode = authCode; } 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); }
public async Task <IActionResult> Create(TriggersDetailViewModel model) { List <int> badgeRequiredList = new List <int>(); List <int> challengeRequiredList = new List <int>(); if (!string.IsNullOrWhiteSpace(model.BadgeRequiredList)) { badgeRequiredList = model.BadgeRequiredList .Replace("<", "") .Split('>') .Where(_ => !string.IsNullOrWhiteSpace(_)) .Select(Int32.Parse) .ToList(); } if (!string.IsNullOrWhiteSpace(model.ChallengeRequiredList)) { challengeRequiredList = model.ChallengeRequiredList .Replace("<", "") .Split('>') .Where(_ => !string.IsNullOrWhiteSpace(_)) .Select(Int32.Parse) .ToList(); } var requirementCount = badgeRequiredList.Count + challengeRequiredList.Count; if (string.IsNullOrWhiteSpace(model.BadgeMakerImage) && model.BadgeUploadImage == null) { ModelState.AddModelError("BadgePath", "A badge is required."); } else if (model.BadgeUploadImage != null && (string.IsNullOrWhiteSpace(model.BadgeMakerImage) || !model.UseBadgeMaker) && (Path.GetExtension(model.BadgeUploadImage.FileName).ToLower() != ".jpg" && Path.GetExtension(model.BadgeUploadImage.FileName).ToLower() != ".jpeg" && Path.GetExtension(model.BadgeUploadImage.FileName).ToLower() != ".png")) { ModelState.AddModelError("BadgeUploadImage", "Please use a .jpg or .png image."); } if (!model.IsSecretCode) { if ((!model.Trigger.Points.HasValue || model.Trigger.Points < 1) && requirementCount < 1) { ModelState.AddModelError("TriggerRequirements", "Points or a Challenge/Trigger item is required."); } else if ((!model.Trigger.ItemsRequired.HasValue || model.Trigger.ItemsRequired < 1) && requirementCount >= 1) { ModelState.AddModelError("Trigger.ItemsRequired", "Please enter how many of the Challenge/Trigger item are required."); } else if (model.Trigger.ItemsRequired > requirementCount) { ModelState.AddModelError("Trigger.ItemsRequired", "Items Required can not be greater than the number of Challenge/Trigger items."); } } else if (string.IsNullOrWhiteSpace(model.Trigger.SecretCode)) { ModelState.AddModelError("Trigger.SecretCode", "The Secret Code field is required."); } else if (await _triggerService.CodeExistsAsync(model.Trigger.SecretCode)) { ModelState.AddModelError("Trigger.SecretCode", "That Secret Code already exists."); } if (ModelState.IsValid) { try { if (model.IsSecretCode) { model.Trigger.Points = null; model.Trigger.ItemsRequired = null; model.Trigger.LimitToSystemId = null; model.Trigger.LimitToBranchId = null; model.Trigger.LimitToProgramId = null; model.Trigger.SecretCode = model.Trigger.SecretCode.Trim().ToLower(); model.Trigger.BadgeIds = new List <int>(); model.Trigger.ChallengeIds = new List <int>(); } else { model.Trigger.SecretCode = null; model.Trigger.BadgeIds = badgeRequiredList; model.Trigger.ChallengeIds = challengeRequiredList; } if (model.BadgeUploadImage != null || !string.IsNullOrWhiteSpace(model.BadgeMakerImage)) { byte[] badgeBytes; string filename; if (!string.IsNullOrWhiteSpace(model.BadgeMakerImage) && (model.BadgeUploadImage != null || model.UseBadgeMaker)) { var badgeString = model.BadgeMakerImage.Split(',').Last(); badgeBytes = Convert.FromBase64String(badgeString); filename = "badge.png"; } else { using (var fileStream = model.BadgeUploadImage.OpenReadStream()) { using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); badgeBytes = ms.ToArray(); } } filename = Path.GetFileName(model.BadgeUploadImage.FileName); } Badge newBadge = new Badge() { Filename = filename }; var badge = await _badgeService.AddBadgeAsync(newBadge, badgeBytes); model.Trigger.AwardBadgeId = badge.Id; } var trigger = await _triggerService.AddAsync(model.Trigger); ShowAlertSuccess($"Trigger '<strong>{trigger.Name}</strong>' was successfully created"); return(RedirectToAction("Index")); } catch (GraException gex) { ShowAlertWarning("Unable to add trigger: ", gex.Message); } } model.Action = "Create"; model.SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"); if (model.Trigger.LimitToSystemId.HasValue) { model.BranchList = new SelectList( (await _siteService.GetBranches(model.Trigger.LimitToSystemId.Value)), "Id", "Name"); } else { model.BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"); } model.ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name"); model.VendorCodeTypeList = new SelectList( (await _vendorCodeService.GetTypeAllAsync()), "Id", "Name"); model.TriggerRequirements = await _triggerService .GetRequirementsByIdsAsync(badgeRequiredList, challengeRequiredList); foreach (var requirement in model.TriggerRequirements) { requirement.BadgePath = _pathResolver.ResolveContentPath(requirement.BadgePath); } PageTitle = "Create Trigger"; return(View("Detail", model)); }
public async Task <IActionResult> Index() { string authCode = null; var useAuthCode = TempData.ContainsKey(EnteredAuthCode); if (useAuthCode) { authCode = (string)TempData[EnteredAuthCode]; } var site = await GetCurrentSiteAsync(); if (!site.SinglePageSignUp) { return(RedirectToAction("Step1")); } var siteStage = GetSiteStage(); if (useAuthCode == false) { if (siteStage == SiteStage.BeforeRegistration) { if (site.RegistrationOpens.HasValue) { AlertInfo = $"You can join {site.Name} on {site.RegistrationOpens.Value.ToString("d")}"; } else { AlertInfo = $"Registration for {site.Name} has not opened yet"; } return(RedirectToAction("Index", "Home")); } else if (siteStage >= SiteStage.ProgramEnded) { AlertInfo = $"{site.Name} has ended, please join us next time!"; return(RedirectToAction("Index", "Home")); } } PageTitle = $"{site.Name} - Join Now!"; var systemList = await _siteService.GetSystemList(); var programList = await _siteService.GetProgramList(); var programViewObject = _mapper.Map <List <ProgramViewModel> >(programList); var districtList = await _schoolService.GetDistrictsAsync(true); SinglePageViewModel viewModel = new SinglePageViewModel() { RequirePostalCode = site.RequirePostalCode, ProgramJson = Newtonsoft.Json.JsonConvert.SerializeObject(programViewObject), SystemList = new SelectList(systemList.ToList(), "Id", "Name"), ProgramList = new SelectList(programList.ToList(), "Id", "Name"), CategorySelectionAction = nameof(SchoolCategory), PublicSelected = true, ShowPrivateOption = await _schoolService.AnyPrivateSchoolsAsync(), ShowCharterOption = await _schoolService.AnyCharterSchoolsAsync(), SchoolDistrictList = new SelectList(districtList.ToList(), "Id", "Name"), AskEmailReminder = siteStage == SiteStage.RegistrationOpen && await GetSiteSettingBoolAsync(SiteSettingKey.Users.AskPreregistrationReminder) }; var askIfFirstTime = await GetSiteSettingBoolAsync(SiteSettingKey.Users.AskIfFirstTime); if (askIfFirstTime) { viewModel.AskFirstTime = EmptyNoYes(); } var(askActivityGoal, defaultDailyGoal) = await GetSiteSettingIntAsync( SiteSettingKey.Users.DefaultDailyPersonalGoal); if (askActivityGoal) { viewModel.DailyPersonalGoal = defaultDailyGoal; var pointTranslation = programList.First().PointTranslation; viewModel.TranslationDescriptionPastTense = pointTranslation.TranslationDescriptionPastTense.Replace("{0}", "").Trim(); viewModel.ActivityDescriptionPlural = pointTranslation.ActivityDescriptionPlural; } if (systemList.Count() == 1) { var systemId = systemList.SingleOrDefault().Id; var branchList = await _siteService.GetBranches(systemId); if (branchList.Count() > 1) { branchList = branchList.Prepend(new Branch() { Id = -1 }); } else { viewModel.BranchId = branchList.SingleOrDefault().Id; } viewModel.BranchList = new SelectList(branchList.ToList(), "Id", "Name"); viewModel.SystemId = systemId; } if (programList.Count() == 1) { var programId = programList.SingleOrDefault().Id; var program = await _siteService.GetProgramByIdAsync(programId); viewModel.ProgramId = programList.SingleOrDefault().Id; viewModel.ShowAge = program.AskAge; viewModel.ShowSchool = program.AskSchool; } if (useAuthCode) { viewModel.AuthorizationCode = authCode; } return(View(viewModel)); }
public async Task <IActionResult> Detail(int id) { try { var user = await _userService.GetDetails(id); SetPageTitle(user); var branchList = await _siteService.GetBranches(user.SystemId); var systemList = await _siteService.GetSystemList(); var programList = await _siteService.GetProgramList(); var userProgram = programList.Where(_ => _.Id == user.ProgramId).SingleOrDefault(); var programViewObject = _mapper.Map <List <ProgramViewModel> >(programList); ParticipantsDetailViewModel viewModel = new ParticipantsDetailViewModel() { User = user, Id = user.Id, HouseholdCount = await _userService .FamilyMemberCountAsync(user.HouseholdHeadUserId ?? id), HeadOfHouseholdId = user.HouseholdHeadUserId, HasAccount = !string.IsNullOrWhiteSpace(user.Username), CanEditDetails = UserHasPermission(Permission.EditParticipants), RequirePostalCode = (await GetCurrentSiteAsync()).RequirePostalCode, ShowAge = userProgram.AskAge, ShowSchool = userProgram.AskSchool, HasSchoolId = user.SchoolId.HasValue, ProgramJson = Newtonsoft.Json.JsonConvert.SerializeObject(programViewObject), BranchList = new SelectList(branchList.ToList(), "Id", "Name"), ProgramList = new SelectList(programList.ToList(), "Id", "Name"), SystemList = new SelectList(systemList.ToList(), "Id", "Name") }; var districtList = await _schoolService.GetDistrictsAsync(); if (user.SchoolId.HasValue) { var schoolDetails = await _schoolService.GetSchoolDetailsAsync(user.SchoolId.Value); var typeList = await _schoolService.GetTypesAsync(schoolDetails.SchoolDisctrictId); viewModel.SchoolDistrictList = new SelectList(districtList.ToList(), "Id", "Name", schoolDetails.SchoolDisctrictId); viewModel.SchoolTypeList = new SelectList(typeList.ToList(), "Id", "Name", schoolDetails.SchoolTypeId); viewModel.SchoolList = new SelectList(schoolDetails.Schools.ToList(), "Id", "Name"); } else { viewModel.SchoolDistrictList = new SelectList(districtList.ToList(), "Id", "Name"); } return(View(viewModel)); } catch (GraException gex) { ShowAlertWarning("Unable to view participant: ", gex); return(RedirectToAction("Index")); } }
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() { var site = await GetCurrentSiteAsync(); if (!site.SinglePageSignUp) { return(RedirectToAction("Step1")); } var siteStage = GetSiteStage(); if (siteStage == SiteStage.BeforeRegistration) { if (site.RegistrationOpens.HasValue) { AlertInfo = $"You can join {site.Name} on {site.RegistrationOpens.Value.ToString("d")}"; } else { AlertInfo = $"Registration for {site.Name} has not opened yet"; } return(RedirectToAction("Index", "Home")); } else if (siteStage >= SiteStage.ProgramEnded) { AlertInfo = $"{site.Name} has ended, please join us next time!"; return(RedirectToAction("Index", "Home")); } PageTitle = $"{site.Name} - Join Now!"; var systemList = await _siteService.GetSystemList(); var programList = await _siteService.GetProgramList(); var programViewObject = _mapper.Map <List <ProgramViewModel> >(programList); var districtList = await _schoolService.GetDistrictsAsync(); SinglePageViewModel viewModel = new SinglePageViewModel() { RequirePostalCode = site.RequirePostalCode, ProgramJson = Newtonsoft.Json.JsonConvert.SerializeObject(programViewObject), SystemList = new SelectList(systemList.ToList(), "Id", "Name"), ProgramList = new SelectList(programList.ToList(), "Id", "Name"), SchoolDistrictList = new SelectList(districtList.ToList(), "Id", "Name") }; if (systemList.Count() == 1) { var systemId = systemList.SingleOrDefault().Id; var branchList = await _siteService.GetBranches(systemId); if (branchList.Count() > 1) { branchList = branchList.Prepend(new Branch() { Id = -1 }); } else { viewModel.BranchId = branchList.SingleOrDefault().Id; } viewModel.BranchList = new SelectList(branchList.ToList(), "Id", "Name"); viewModel.SystemId = systemId; } if (programList.Count() == 1) { var programId = programList.SingleOrDefault().Id; var program = await _siteService.GetProgramByIdAsync(programId); viewModel.ProgramId = programList.SingleOrDefault().Id; viewModel.ShowAge = program.AskAge; viewModel.ShowSchool = program.AskSchool; } return(View(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)); }