public async Task <IActionResult> CreateChallenge(CreateChallengeViewModel model) { var accessToken = HttpContext.Request.Headers["Authorization"].ToString().GetAccessTokenFromHeaderString(); var userProfile = await _identityService.GetUserProfileByAccessToken(accessToken); if (userProfile.UserType == UserType.Basic && model.Range != 0 && model.Sex != Gender.Unknown) { return(Unauthorized(_localizer.GetString("NotPremium"))); } var challengeParams = new ChallengeParams(Status.Active, userProfile.Id, model.BetAmount, model.IsBotActivated); var challenge = _challengeService.CreateOrUpdate(challengeParams); var challengerIds = await _challengeRequestService .CreateChallengeRequests( new CreateChallengeRequestModel( accessToken, challenge.Id, userProfile.Id, challenge.RewardPoint, model.Range, model.Sex, model.IsBotActivated)); if (challengerIds == null || challengerIds.Count == 0) { _challengeService.Remove(new RemoveEntityParams(challenge.Id, new HasOperator(), true, true)); return(BadRequest(_localizer.GetString("NoUserFound"))); } return(Ok(challengeParams)); }
public async Task CreateChallenge(CreateChallengeViewModel model) { //var accessToken = HttpContext.Token; //var userId = await _challengeService.GetUserId(accessToken); //var challengeParams = new ChallengeParams(ServiceBase.Enums.Status.Active, userId); //var challenge = _challengeService.CreateOrUpdate(challengeParams); //await Clients.Users(userIds).SendAsync("ReceiveMessage", body); }
public ActionResult Create(CreateChallengeViewModel model) { if (!ModelState.IsValid) { return(View(PopulateViewDataForCreateChallenge(model))); } var challenge = mapper.Map <CreateChallengeViewModel, Challenge>(model); uow.Challenges.Add(challenge); uow.Commit(); return(RedirectToAction("Index")); }
private CreateChallengeViewModel PopulateViewDataForCreateChallenge(CreateChallengeViewModel viewModel = null) { var model = viewModel ?? new CreateChallengeViewModel(); model.CategoryPicker = uow.CategoriesRepository.PickList.ToSelectList(); model.TrackPicker = uow.MissionTracks.PickList.ToSelectList(); var imagesInStore = store.EnumerateImages(); var imagePickList = imagesInStore.Select(p => new PickListItem <string> { Id = p, DisplayName = p }); model.ValidationImagePicker = imagePickList.ToSelectList(); return(model); }
public ActionResult Edit(CreateChallengeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var id = model.Id; var maybeChallenge = uow.Challenges.GetMaybe(id); var original = maybeChallenge.Single(); mapper.Map(model, original); uow.Commit(); return(RedirectToAction("Index")); }