Esempio n. 1
0
        public async Task <IReadOnlyList <string> > CreateChallengeRequests(CreateChallengeRequestModel model)
        {
            var filterUsersViewModel = new FilterUsersViewModel(model.ChallengeOwnerId, model.Points, model.Range, model.IsBotActivated);
            var userIds = await GetChallengerIds(
                new GetChallengerIdsModel(
                    model.AccessToken,
                    filterUsersViewModel,
                    AppSettingsProvider.LoyaltyBaseUrl,
                    AppSettingsProvider.FilterUsersUrl));

            //var filteredUserId = ExcludeOutOfRangeUsers(model.Range, model.ChallengeOwnerId, userIds);
            //filteredUserId = ApplyGenderFilter(model.Gender, model.ChallengeOwnerId, filteredUserId);

            foreach (var userId in userIds)
            {
                var challengeRequestParams = new ChallengeRequestParams(Status.Active, model.ChallengeOwnerId, userId, model.ChallengeId, Enums.ChallengeRequestStatus.Waiting);
                CreateOrUpdate(challengeRequestParams);

                await _hubContext.Clients.User(userId)
                .SendAsync("ChallengeRequestReceived", JsonConvert.SerializeObject(GetChallengeRequest(challengeRequestParams.Id)));
            }

            if (model.IsBotActivated)
            {
                var acceptingUserId  = userIds.FirstOrDefault();
                var botUser          = _userService.GetUserByUserId(acceptingUserId);
                var challengeRequest = Entities.FirstOrDefault(x => x.ChallengeId == model.ChallengeId && x.ChallengerId == acceptingUserId && x.ChallengeOwnerId == model.ChallengeOwnerId);

                await BotActivationAsync(model, challengeRequest.Id, botUser.Nickname);
            }

            return(userIds);
        }
Esempio n. 2
0
        private async Task CreateChallengeRequestForUser(CreateChallengeRequestForUserModel model)
        {
            var challengeRequestParams = new ChallengeRequestParams(Status.Active, model.ChallengeOwnerId, model.ChallengerId, model.ChallengeId, Enums.ChallengeRequestStatus.Waiting);

            CreateOrUpdate(challengeRequestParams);

            await _hubContext.Clients.Users(model.ChallengerId)
            .SendAsync("ChallengeRequestReceived", JsonConvert.SerializeObject(GetChallengeRequest(challengeRequestParams.Id)));
        }
Esempio n. 3
0
        private List <string> SetChallengeRequestsToMissed(int challengeId, int challengeRequestId)
        {
            var challengeRequestIds = Entities.Where(x => x.ChallengeId == challengeId && x.Id != challengeRequestId).Select(x => x.Id).ToList();

            var userIds = new List <string>();
            ChallengeRequestParams challengeRequestParams = new ChallengeRequestParams();

            foreach (var id in challengeRequestIds)
            {
                var challengeRequest = Get(id);
                challengeRequestParams = _mapper.Map <ChallengeRequest, ChallengeRequestParams>(challengeRequest);
                challengeRequestParams.ChallengeRequestStatus = Enums.ChallengeRequestStatus.Missed;
                CreateOrUpdate(challengeRequestParams);

                userIds.Add(challengeRequest.ChallengerId);
            }

            return(userIds);
        }