public async Task <IActionResult> Create() { var site = await GetCurrentSiteAsync(); var siteUrl = await _siteService.GetBaseUrl(Request.Scheme, Request.Host.Value); var viewModel = new TriggersDetailViewModel { Action = "Create", IsSecretCode = true, BadgeMakerUrl = GetBadgeMakerUrl(siteUrl, site.FromEmailAddress), UseBadgeMaker = true, EditAvatarBundle = UserHasPermission(Permission.ManageAvatars), EditMail = UserHasPermission(Permission.ManageTriggerMail), EditVendorCode = UserHasPermission(Permission.ManageVendorCodes), SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"), BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"), ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name") }; if (viewModel.EditVendorCode) { viewModel.VendorCodeTypeList = new SelectList( (await _vendorCodeService.GetTypeAllAsync()), "Id", "Description"); } if (viewModel.EditAvatarBundle) { viewModel.UnlockableAvatarBundleList = new SelectList( await _dynamicAvatarService.GetAllBundlesAsync(true), "Id", "Name"); } PageTitle = "Create Trigger"; return(View("Detail", viewModel)); }
public async Task <IActionResult> CriteriaCreate() { PageTitle = "Drawing Criteria"; CriterionDetailViewModel viewModel = new CriterionDetailViewModel() { SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"), BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"), ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name"), }; return(View(viewModel)); }
private async Task <ChallengesDetailViewModel> GetDetailLists(ChallengesDetailViewModel model) { var systemList = (await _siteService.GetSystemList()) .OrderByDescending(_ => _.Id == GetId(ClaimType.SystemId)) .ThenBy(_ => _.Name); model.SystemList = new SelectList(systemList, "Id", "Name"); var programList = (await _siteService.GetProgramList()); model.ProgramList = new SelectList(programList, "Id", "Name"); if (model.Challenge?.LimitToSystemId.HasValue == true) { var branchList = (await _siteService .GetBranches(model.Challenge.LimitToSystemId.Value)) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); model.BranchList = new SelectList(branchList, "Id", "Name"); } else { var branchList = (await _siteService.GetAllBranches()) .OrderByDescending(_ => _.Id == GetId(ClaimType.BranchId)) .ThenBy(_ => _.Name); model.BranchList = new SelectList(branchList, "Id", "Name"); } return(model); }
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))); }
Generate(int siteId, int count) { var branches = await _siteService.GetAllBranches(true); var programs = await _siteService.GetProgramList(); var schools = await _schoolService.GetSchoolsAsync(); var testUsers = new Faker <Domain.Model.User>() .Rules((f, u) => { var branch = f.PickRandom(branches); var program = f.PickRandom(programs); u.BranchId = branch.Id; if (f.Random.Bool()) { u.Email = f.Person.Email; } u.FirstName = f.Person.FirstName; u.LastName = f.Person.LastName; if (f.Random.Bool()) { u.PhoneNumber = f.Phone.PhoneNumber("###-###-####"); } u.PostalCode = f.Address.ZipCode(); u.ProgramId = program.Id; u.SiteId = siteId; u.SystemId = branch.SystemId; u.Username = f.Person.UserName; if (program.AskAge && (f.Random.Bool() || program.AgeRequired)) { u.Age = f.Random.Number(0, 104); } if (program.AskSchool && (f.Random.Bool() || program.SchoolRequired)) { var school = f.PickRandom(schools); u.SchoolId = school.Id; } }); var rand = new Bogus.Randomizer(); var users = new List <GeneratedUser>(); for (int i = 0; i < count; i++) { var user = testUsers.Generate(); users.Add(new GeneratedUser { User = user, Password = "******" }); } return(users); }
public async Task <IActionResult> Configure(int id) { var report = _reportService.GetReportList().SingleOrDefault(_ => _.Id == id); if (report == null) { AlertDanger = $"Could not find report of type {id}."; return(RedirectToAction("Index")); } PageTitle = $"Configure {report.Name}"; string viewName = report.Name.Replace(" ", string.Empty); if (viewName.EndsWith("Report")) { viewName = viewName.Substring(0, viewName.Length - 6); } var systemList = await _siteService.GetSystemList(true); var branchList = await _siteService.GetAllBranches(true); var programList = await _siteService.GetProgramList(); var schoolDistrictList = await _schoolService.GetDistrictsAsync(); var schoolList = await _schoolService.GetSchoolsAsync(schoolDistrictList.FirstOrDefault()?.Id); var groupInfoList = await _userService.GetGroupInfosAsync(); var vendorCodeTypeList = await _vendorCodeService.GetTypeAllAsync(); var site = await GetCurrentSiteAsync(); var triggerList = await _triggerService.GetTriggersAwardingPrizesAsync(); foreach (var trigger in triggerList) { trigger.AwardPrizeName += $" ({trigger.Name})"; } return(View($"{viewName}Criteria", new ReportCriteriaViewModel { ReportId = id, ProgramStartDate = site.ProgramStarts ?? new DateTime(2018, 01, 01), SystemList = new SelectList(systemList, "Id", "Name"), BranchList = new SelectList(branchList, "Id", "Name"), ProgramList = new SelectList(programList, "Id", "Name"), SchoolDistrictList = new SelectList(schoolDistrictList, "Id", "Name"), SchoolList = new SelectList(schoolList, "Id", "Name"), GroupInfosList = new SelectList(groupInfoList, "Id", "Name"), VendorCodeTypeList = new SelectList(vendorCodeTypeList, "Id", "Description"), PrizeList = new SelectList(triggerList, "Id", "AwardPrizeName") })); }
public async Task <IActionResult> Create() { var site = await GetCurrentSiteAsync(); var siteUrl = await _siteService.GetBaseUrl(Request.Scheme, Request.Host.Value); TriggersDetailViewModel viewModel = new TriggersDetailViewModel() { Action = "Create", IsSecretCode = true, BadgeMakerUrl = GetBadgeMakerUrl(siteUrl, site.FromEmailAddress), UseBadgeMaker = true, SystemList = new SelectList((await _siteService.GetSystemList()), "Id", "Name"), BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"), ProgramList = new SelectList((await _siteService.GetProgramList()), "Id", "Name"), VendorCodeTypeList = new SelectList( (await _vendorCodeService.GetTypeAllAsync()), "Id", "Name") }; PageTitle = "Create Trigger"; return(View("Detail", viewModel)); }
public async Task <IActionResult> Configure(int id) { var report = _reportService.GetReportList().Where(_ => _.Id == id).SingleOrDefault(); if (report == null) { AlertDanger = $"Could not find report of type {id}."; return(RedirectToAction("Index")); } PageTitle = $"Configure {report.Name}"; string viewName = report.Name.Replace(" ", string.Empty); if (viewName.EndsWith("Report")) { viewName = viewName.Substring(0, viewName.Length - 6); } var systemList = await _siteService.GetSystemList(true); var branchList = await _siteService.GetAllBranches(true); var programList = await _siteService.GetProgramList(); var schoolDistrictList = await _schoolService.GetDistrictsAsync(); var schoolList = await _schoolService.GetSchoolsAsync(schoolDistrictList.FirstOrDefault()?.Id); return(View($"{viewName}Criteria", new ReportCriteriaViewModel { ReportId = id, SystemList = new SelectList(systemList, "Id", "Name"), BranchList = new SelectList(branchList, "Id", "Name"), ProgramList = new SelectList(programList, "Id", "Name"), SchoolDistrictList = new SelectList(schoolDistrictList, "Id", "Name"), SchoolList = new SelectList(schoolList, "Id", "Name"), })); }
public async Task <IActionResult> Step1() { var site = await GetCurrentSiteAsync(); if (site.SinglePageSignUp) { return(RedirectToAction("Index")); } 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(); Step1ViewModel viewModel = new Step1ViewModel() { RequirePostalCode = site.RequirePostalCode, SystemList = new SelectList(systemList.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; } else { viewModel.BranchList = new SelectList(await _siteService.GetAllBranches(true), "Id", "Name"); } return(View(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> Step1() { string authCode = null; var useAuthCode = TempData.ContainsKey(EnteredAuthCode); if (useAuthCode) { authCode = (string)TempData[EnteredAuthCode]; } var site = await GetCurrentSiteAsync(); if (site.SinglePageSignUp) { return(RedirectToAction(nameof(Index))); } if (!useAuthCode) { var siteStage = GetSiteStage(); 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 viewModel = new Step1ViewModel { RequirePostalCode = site.RequirePostalCode, SystemList = NameIdSelectList(systemList.ToList()) }; 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; } else { viewModel.BranchList = NameIdSelectList(await _siteService.GetAllBranches(true)); } if (useAuthCode) { viewModel.AuthorizationCode = authCode; } return(View(viewModel)); }