public async Task <ChallengeGroup> AddSaveAsync(int userId, ChallengeGroup challengeGroup, IEnumerable <int> challengeIds) { var newChallengeGroup = await base.AddSaveAsync(userId, challengeGroup); if (challengeIds.Any()) { var time = _dateTimeProvider.Now; var challengeGroupChallengeList = new List <Model.ChallengeGroupChallenge>(); foreach (var challengeId in challengeIds) { challengeGroupChallengeList.Add(new Model.ChallengeGroupChallenge() { ChallengeGroupId = newChallengeGroup.Id, ChallengeId = challengeId, CreatedAt = time, CreatedBy = userId }); } await _context.ChallengeGroupChallenges.AddRangeAsync(challengeGroupChallengeList); await _context.SaveChangesAsync(); } return(newChallengeGroup); }
public async Task <ChallengeGroup> UpdateSaveAsync(int userId, ChallengeGroup challengeGroup, IEnumerable <int> challengesToAdd, IEnumerable <int> challengesToRemove) { await base.UpdateAsync(userId, challengeGroup); if (challengesToAdd?.Any() == true) { var time = _dateTimeProvider.Now; var challengeGroupChallengeList = new List <Model.ChallengeGroupChallenge>(); foreach (var challengeId in challengesToAdd) { challengeGroupChallengeList.Add(new Model.ChallengeGroupChallenge() { ChallengeGroupId = challengeGroup.Id, ChallengeId = challengeId, CreatedAt = time, CreatedBy = userId }); } await _context.ChallengeGroupChallenges.AddRangeAsync(challengeGroupChallengeList); } if (challengesToRemove?.Count() > 0) { var removeList = _context.ChallengeGroupChallenges .Where(_ => _.ChallengeGroupId == challengeGroup.Id && challengesToRemove.Contains(_.ChallengeId)); _context.ChallengeGroupChallenges.RemoveRange(removeList); } await _context.SaveChangesAsync(); return(challengeGroup); }
AddGroupAsync(ChallengeGroup challengeGroup, List <int> ChallengeIds) { VerifyPermission(Permission.AddChallengeGroups); var siteId = GetCurrentSiteId(); var stub = challengeGroup.Stub.Trim().ToLower(); var existingStub = await _challengeGroupRepository.StubInUseAsync(siteId, stub); if (existingStub) { throw new GraException($"A challenge group with the link {stub} already exists."); } var serviceResult = new ServiceResult <ChallengeGroup>(); challengeGroup.SiteId = siteId; challengeGroup.Stub = stub; var validChallengeIds = await _challengeRepository.ValidateChallengeIdsAsync(siteId, ChallengeIds); if (ChallengeIds.Count != validChallengeIds.Count()) { serviceResult.Status = ServiceResultStatus.Warning; serviceResult.Message = "One or more of the selected challenges could not be added to this group."; } serviceResult.Data = await _challengeGroupRepository.AddSaveAsync( GetClaimId(ClaimType.UserId), challengeGroup, validChallengeIds); return(serviceResult); }
public async Task <ServiceResult <ChallengeGroup> > EditGroupAsync( ChallengeGroup challengeGroup, List <int> ChallengeIds) { VerifyPermission(Permission.EditChallengeGroups); var siteId = GetCurrentSiteId(); var serviceResult = new ServiceResult <ChallengeGroup>(); var currentChallengeGroup = await _challengeGroupRepository.GetByIdAsync( challengeGroup.Id); challengeGroup.SiteId = currentChallengeGroup.SiteId; challengeGroup.Stub = currentChallengeGroup.Stub; var validChallengeIds = await _challengeRepository.ValidateChallengeIdsAsync(siteId, ChallengeIds); if (ChallengeIds.Count != validChallengeIds.Count()) { serviceResult.Status = ServiceResultStatus.Warning; serviceResult.Message = "One or more of the selected challenges could not be added to this group."; } var challengesToAdd = ChallengeIds.Except(currentChallengeGroup.ChallengeIds); var challengesToRemove = currentChallengeGroup.ChallengeIds.Except(ChallengeIds); serviceResult.Data = await _challengeGroupRepository.UpdateSaveAsync( GetClaimId(ClaimType.UserId), challengeGroup, challengesToAdd, challengesToRemove); return(serviceResult); }
private void Start() { string _lastChallengeName = PlayerPrefs.GetString("nowChallenge"); ChallengeGroup _lastGroup = null; ChallengeData _lastChallenge = null; foreach (var _group in challengeGroups) { foreach (var _challenge in _group.challenges) { if (_challenge.title == _lastChallengeName) { _lastGroup = _group; _lastChallenge = _challenge; break; } } } if (_lastChallenge != null) { ToChallenge(_lastGroup, _lastChallenge, true); } else { ToMenu(true); } }
//public int index { get; private set; } public void init(ChallengeGroup p_group, ChallengeData p_challenge) { challenge = p_challenge; group = p_group; title.text = string.Format("{0:00} ", challenge.index) + challenge.title; RefreahState(); MainManager.challengeButDict.Add(p_challenge.name, this); }
public static void ToChallenge(ChallengeGroup p_group, ChallengeData p_challenge, bool p_Immediately = false) { state = E_STATE.Challenge; challengeResultBox.ClearResult(); challengeView.Show(p_group, p_challenge); instance.RunChallenge(p_challenge); PlayerPrefs.SetString("nowChallenge", p_challenge.title); instance.animator.Play("ToChallenge", 0, p_Immediately ? 1 : 0); }
internal void init(ChallengeGroup p_group) { challengeGroup = p_group; title.text = p_group.index.ToString("00 ") + p_group.title; foreach (var _challenge in challengeGroup.challenges) { var _challengeBut = Instantiate(challengeButPrefab, transform); _challengeBut.init(challengeGroup, _challenge); } }
internal void Show(ChallengeGroup p_group, ChallengeData p_challenge) { if ((p_group != null) && (p_challenge != null)) { group = p_group; challenge = p_challenge; title.text = $"{group.index:00}-{challenge.index:00}\n{challenge.title}"; description.text = challenge.description; description.alignment = (challenge.description.Contains("}")) ? TextAnchor.UpperLeft : TextAnchor.UpperCenter; tipButton.gameObject.SetActive(challenge.tip != null); } else { group = null; challenge = null; title.text = ""; description.text = ""; } }
public async Task <IActionResult> Index(string Search = null, int?Program = null, string Categories = null, string Group = null, bool Favorites = false, string Status = null, int page = 1, ChallengeFilter.OrderingOption ordering = ChallengeFilter.OrderingOption.MostPopular, System.Net.HttpStatusCode httpStatus = System.Net.HttpStatusCode.OK) { var filter = new ChallengeFilter(page) { Ordering = ordering }; if (!string.IsNullOrWhiteSpace(Search)) { filter.Search = Search; } if (Program.HasValue) { filter.ProgramIds = new List <int?> { Program }; } if (!string.IsNullOrWhiteSpace(Categories)) { var categoryIds = new List <int>(); foreach (var category in Categories.Split(',')) { if (int.TryParse(category, out int result)) { categoryIds.Add(result); } } filter.CategoryIds = categoryIds; } if (AuthUser.Identity.IsAuthenticated) { filter.Favorites = Favorites; if (string.IsNullOrWhiteSpace(Status) || string.Equals(Status, StatusUncompleted, StringComparison.OrdinalIgnoreCase)) { filter.IsCompleted = false; } else if (string.Equals(Status, StatusCompleted, StringComparison.OrdinalIgnoreCase)) { filter.IsCompleted = true; } } ChallengeGroup challengeGroup = null; if (!string.IsNullOrWhiteSpace(Group)) { challengeGroup = await _challengeService.GetActiveGroupByStubAsync(Group); if (challengeGroup != null) { filter.GroupId = challengeGroup.Id; } PageTitle = _sharedLocalizer[Annotations.Title.ChallengeGroup, challengeGroup.Name]; } var challengeList = await _challengeService.GetPaginatedChallengeListAsync(filter); var paginateModel = new PaginateViewModel { ItemCount = challengeList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.PastMaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } foreach (var challenge in challengeList.Data) { if (!string.IsNullOrEmpty(challenge.BadgeFilename)) { challenge.BadgeFilename = _pathResolver .ResolveContentPath(challenge.BadgeFilename); } if (challenge.IsCompleted == true) { challenge.Status = _sharedLocalizer[Annotations.Interface.Completed]; } } var siteStage = GetSiteStage(); var isActive = siteStage == SiteStage.ProgramOpen || siteStage == SiteStage.ProgramEnded; var categoryList = await _categoryService.GetListAsync(true); var featuredChallengeGroups = await _challengeService .GetActiveFeaturedChallengeGroupsAsync(); var viewModel = new ChallengesListViewModel { Categories = Categories, CategoryIds = filter.CategoryIds, CategoryList = new SelectList(categoryList, "Id", "Name"), ChallengeGroup = challengeGroup, Challenges = challengeList.Data.ToList(), Favorites = Favorites, FeaturedChallengeGroups = featuredChallengeGroups, IsActive = isActive, IsLoggedIn = AuthUser.Identity.IsAuthenticated, Ordering = filter.Ordering, PaginateModel = paginateModel, Program = Program, ProgramList = new SelectList(await _siteService.GetProgramList(), "Id", "Name"), Search = Search, Status = Status }; if (!string.IsNullOrWhiteSpace(Search)) { HttpContext.Session.SetString(SessionKey.ChallengeSearch, Search); } else { HttpContext.Session.Remove(SessionKey.ChallengeSearch); } HttpContext.Session.SetInt32(SessionKey.ChallengePage, page); if (httpStatus != System.Net.HttpStatusCode.OK) { Response.StatusCode = (int)httpStatus; } return(View(nameof(Index), viewModel)); }
public async Task <IActionResult> Index(string Search, string Categories, string Group, bool Favorites = false, int page = 1) { int siteId = GetCurrentSiteId(); ChallengeFilter filter = new ChallengeFilter(page); if (!string.IsNullOrWhiteSpace(Search)) { filter.Search = Search; } if (!string.IsNullOrWhiteSpace(Categories)) { var categoryIds = new List <int>(); foreach (var category in Categories.Split(',')) { int result; if (int.TryParse(category, out result)) { categoryIds.Add(result); } } filter.CategoryIds = categoryIds; } if (Favorites == true && AuthUser.Identity.IsAuthenticated) { filter.Favorites = true; } ChallengeGroup challengeGroup = null; if (!string.IsNullOrWhiteSpace(Group)) { challengeGroup = await _challengeService.GetActiveGroupByStubAsync(Group); if (challengeGroup != null) { filter.GroupId = challengeGroup.Id; } } var challengeList = await _challengeService.GetPaginatedChallengeListAsync(filter); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = challengeList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } foreach (var challenge in challengeList.Data) { if (!string.IsNullOrEmpty(challenge.BadgeFilename)) { challenge.BadgeFilename = _pathResolver.ResolveContentPath(challenge.BadgeFilename); } if (challenge.IsCompleted == true) { challenge.Status = "Completed!"; } } var siteStage = GetSiteStage(); var isActive = (siteStage == SiteStage.ProgramOpen || siteStage == SiteStage.ProgramEnded); var categoryList = await _categoryService.GetListAsync(true); ChallengesListViewModel viewModel = new ChallengesListViewModel() { Challenges = challengeList.Data.ToList(), ChallengeGroup = challengeGroup, PaginateModel = paginateModel, Search = Search, Categories = Categories, Favorites = Favorites, IsActive = isActive, IsLoggedIn = AuthUser.Identity.IsAuthenticated, CategoryIds = filter.CategoryIds, CategoryList = new SelectList(categoryList, "Id", "Name") }; if (!string.IsNullOrWhiteSpace(Search)) { HttpContext.Session.SetString(SessionKey.ChallengeSearch, Search); } else { HttpContext.Session.Remove(SessionKey.ChallengeSearch); } HttpContext.Session.SetInt32(SessionKey.ChallengePage, page); return(View(nameof(Index), viewModel)); }