コード例 #1
0
ファイル: HelpChoice.cs プロジェクト: Lanayx/RadrugaCloud
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{MissionCompletionResult}.</returns>
        public async Task <MissionCompletionResult> ProcessRequest(MissionRequest request)
        {
            var userAnswer = request.Proof.CreatedText.ToLower();

            if ((userAnswer.Contains("мам") && !userAnswer.Contains("друг")) ||
                (userAnswer.Contains("друг") && !userAnswer.Contains("мам")))
            {
                request.StarsCount = 1;
            }
            else if (userAnswer.Contains("мам") && userAnswer.Contains("друг") || userAnswer.Contains("обоим") ||
                     userAnswer.Contains("двоим"))
            {
                request.StarsCount = 3;
            }
            else
            {
                request.DeclineReason = "Это неправильный выбор.";
                await RewardsCalculator.UpdateUserAfterMissionDecline(request, _missionRepository);

                return(new MissionCompletionResult
                {
                    MissionCompletionStatus = MissionCompletionStatus.Fail,
                    Description = request.DeclineReason
                });
            }

            var recievedPoints = await RewardsCalculator.UpdateUserAfterMissionCompletion(request, _missionRepository);

            return(new MissionCompletionResult
            {
                Points = recievedPoints,
                StarsCount = request.StarsCount,
                MissionCompletionStatus = MissionCompletionStatus.Success
            });
        }
コード例 #2
0
ファイル: Censored.cs プロジェクト: Lanayx/RadrugaCloud
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <MissionCompletionResult> ProcessRequest(MissionRequest request)
        {
            if (String.IsNullOrEmpty(request.Proof.CreatedText))
            {
                request.StarsCount = 3;
                var recievedPoints =
                    await RewardsCalculator.UpdateUserAfterMissionCompletion(request, _missionRepository, _appCountersService);

                return(new MissionCompletionResult
                {
                    Points = recievedPoints,
                    StarsCount = request.StarsCount,
                    MissionCompletionStatus = MissionCompletionStatus.Success
                });
            }

            request.DeclineReason = "Увы. В следующий раз постарайся думать своей головой и не совершать глупости";
            await RewardsCalculator.UpdateUserAfterMissionDecline(request, _missionRepository, _appCountersService);

            return(new MissionCompletionResult
            {
                MissionCompletionStatus = MissionCompletionStatus.Fail,
                Description = request.DeclineReason
            });
        }
コード例 #3
0
ファイル: YourBase.cs プロジェクト: Lanayx/RadrugaCloud
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{MissionCompletionResult}.</returns>
        public async Task <MissionCompletionResult> ProcessRequest(MissionRequest request)
        {
            var baseCoordinates = request.Proof.Coordinates.ToArray();

            if (!ValidBaseCoordinates(baseCoordinates, request.User.HomeCoordinate))
            {
                request.DeclineReason = "Координаты базы ошибочны";
                await RewardsCalculator.UpdateUserAfterMissionDecline(request, _missionRepository);

                return(new MissionCompletionResult
                {
                    MissionCompletionStatus = MissionCompletionStatus.Fail,
                    Description = request.DeclineReason
                });
            }

            request.User.BaseNorthCoordinate = baseCoordinates[0];
            request.User.BaseEastCoordinate  = baseCoordinates[1];
            request.User.BaseSouthCoordinate = baseCoordinates[2];
            request.User.BaseWestCoordinate  = baseCoordinates[3];
            request.StarsCount = 3;
            var recievedPoints = await RewardsCalculator.UpdateUserAfterMissionCompletion(request, _missionRepository);

            return(new MissionCompletionResult
            {
                Points = recievedPoints,
                StarsCount = request.StarsCount,
                MissionCompletionStatus = MissionCompletionStatus.Success
            });
        }
コード例 #4
0
ファイル: FriendBase.cs プロジェクト: Lanayx/RadrugaCloud
        /// <summary>
        ///     Processes the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{MissionCompletionResult}.</returns>
        public async Task <MissionCompletionResult> ProcessRequest(MissionRequest request)
        {
            var users = await _userRepository.GetUsers(new QueryOptions <User> {
                Filter = u => u.Id != request.UserId, Select = u => u.HomeCoordinate
            });

            var           coordinates           = users.Select(u => u.HomeCoordinate).Where(coord => coord != null);
            var           passedCoordinate      = request.Proof.Coordinates.First();
            GeoCoordinate friendsBaseCoordinate = null;

            foreach (var geoCoordinate in coordinates)
            {
                var distance = passedCoordinate.GetDistanceTo(geoCoordinate);

                if (distance <= 100)
                {
                    request.StarsCount = 1;
                    if (distance <= 50)
                    {
                        request.StarsCount = 2;
                    }
                    if (distance <= 10)
                    {
                        request.StarsCount = 3;
                    }
                    friendsBaseCoordinate = geoCoordinate;
                    break;
                }
            }

            if (friendsBaseCoordinate == null)
            {
                request.DeclineReason = "Мы не смогли найти ни одного пользователя с таким командным пунктом";
                await RewardsCalculator.UpdateUserAfterMissionDecline(request, _missionRepository, _appCountersService);

                return(new MissionCompletionResult
                {
                    MissionCompletionStatus = MissionCompletionStatus.Fail,
                    Description = request.DeclineReason
                });
            }

            var recievedPoints =
                await
                RewardsCalculator.UpdateUserAfterMissionCompletion(request, _missionRepository, _appCountersService);

            return(new MissionCompletionResult
            {
                Points = recievedPoints,
                StarsCount = request.StarsCount,
                MissionCompletionStatus = MissionCompletionStatus.Success
            });
        }
コード例 #5
0
        public static async Task <MissionCompletionResult> ProcessIncorrectTry(
            MissionRequest request,
            IMissionRepository missionRepository,
            IMissionRequestRepository missionRequestRepository)
        {
            Expression <Func <MissionRequest, bool> > filter =
                a => a.MissionId == request.MissionId && a.UserId == request.UserId;
            var previousRequiests =
                await missionRequestRepository.GetMissionRequests(new QueryOptions <MissionRequest> {
                Filter = filter
            });

            var tryCount = previousRequiests.Count + 1;

            if (tryCount >= request.Mission.TriesFor1Star)
            {
                request.DeclineReason = "Увы, достигнуто максимальное количество попыток.";
                await RewardsCalculator.UpdateUserAfterMissionDecline(request, missionRepository);

                await missionRequestRepository.AddMissionRequest(request);

                return(new MissionCompletionResult
                {
                    MissionCompletionStatus = MissionCompletionStatus.Fail,
                    Description = request.DeclineReason
                });
            }

            var rejectResult = new MissionCompletionResult
            {
                MissionCompletionStatus =
                    MissionCompletionStatus.IntermediateFail,
                TryCount = tryCount
            };

            var failedRequesResult = await missionRequestRepository.AddMissionRequest(request);

            return(failedRequesResult.Status != OperationResultStatus.Success
                       ? MissionCompletionResult.FromOperationResult(failedRequesResult)
                       : rejectResult);
        }
コード例 #6
0
        /// <summary>
        ///     The decline request.
        /// </summary>
        /// <param name="id">
        ///     The id.
        /// </param>
        /// <param name="message">
        ///     The message.
        /// </param>
        /// <returns>
        ///     The <see cref="Task" />.
        /// </returns>
        public async Task <OperationResult> DeclineRequest(string id, string message)
        {
            var missionRequest = await _missionRequestRepository.GetMissionRequest(id);

            if (missionRequest == null || missionRequest.Status != MissionRequestStatus.NotChecked)
            {
                return(OperationResult.NotFound);
            }

            missionRequest.Status        = MissionRequestStatus.Declined;
            missionRequest.DeclineReason = message;

            var result = await _missionRequestRepository.UpdateMissionRequest(missionRequest);

            if (result.Status == OperationResultStatus.Error)
            {
                return(result);
            }

            var oldUserPoints = missionRequest.User.Points;
            await
            RewardsCalculator.UpdateUserAfterMissionDecline(missionRequest, _missionRepository, _appCountersService);

            if (result.Status == OperationResultStatus.Error)
            {
                return(result);
            }

            var finalResult = await _userRepository.UpdateUser(missionRequest.User);

            if (finalResult.Status != OperationResultStatus.Error)
            {
                // new points should always have value
                // ReSharper disable once PossibleInvalidOperationException
                await _ratingService.UpdateUserRating(missionRequest.User, oldUserPoints, missionRequest.User.Points.Value);
            }
            await _notificationService.DeclineMissionNotify(missionRequest.UserId, missionRequest.Mission.Name);

            return(finalResult);
        }
コード例 #7
0
ファイル: HealthySpirit1.cs プロジェクト: Lanayx/RadrugaCloud
        /// <summary>
        ///     Processes the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{MissionCompletionResult}.</returns>
        public async Task <MissionCompletionResult> ProcessRequest(MissionRequest request)
        {
            ushort amount;

            if (!ushort.TryParse(request.Proof.CreatedText, out amount))
            {
                return(new MissionCompletionResult(OperationResultStatus.Error, "Amount is not a number"));
            }
            if (amount > 180 || amount < 10)
            {
                request.DeclineReason = "Не верим!";
                await RewardsCalculator.UpdateUserAfterMissionDecline(request, _missionRepository);

                return(new MissionCompletionResult
                {
                    MissionCompletionStatus = MissionCompletionStatus.Fail,
                    Description = request.DeclineReason
                });
            }

            var dateOfBirth = request.User.DateOfBirth ?? DateTime.UtcNow;

            request.StarsCount = GetStarsBasingOnSexAndAge(
                (DateTime.UtcNow - dateOfBirth).TotalDays / 365,
                request.User.Sex ?? Sex.NotSet,
                amount);

            var recievedPoints = await RewardsCalculator.UpdateUserAfterMissionCompletion(request, _missionRepository);

            return(new MissionCompletionResult
            {
                Points = recievedPoints,
                StarsCount = request.StarsCount,
                MissionCompletionStatus = MissionCompletionStatus.Success
            });
        }
コード例 #8
0
        private async Task <MissionCompletionResult> ProcessGeoCoordinate(MissionRequest request)
        {
            SetStarsAccordingToTime(request);
            var missionFailed  = request.StarsCount == 0;
            int?recievedPoints = null;

            if (missionFailed)
            {
                await RewardsCalculator.UpdateUserAfterMissionDecline(request, _missionRepository, _appCountersService);
            }
            else
            {
                recievedPoints = await RewardsCalculator.UpdateUserAfterMissionCompletion(
                    request,
                    _missionRepository,
                    _appCountersService);
            }


            var requestResult = await _missionRequestRepository.AddMissionRequest(request);

            if (requestResult.Status == OperationResultStatus.Success)
            {
                return(new MissionCompletionResult
                {
                    Points = recievedPoints,
                    StarsCount = request.StarsCount,
                    MissionCompletionStatus =
                        missionFailed
                                       ? MissionCompletionStatus.Fail
                                       : MissionCompletionStatus.Success
                });
            }

            return(MissionCompletionResult.FromOperationResult(requestResult));
        }
コード例 #9
0
        /// <summary>
        ///     Declines the mission.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="missionId">The mission identifier.</param>
        /// <returns>
        ///     Task{OperationResult}.
        /// </returns>
        public async Task <MissionCompletionResult> DeclineMission(string userId, string missionId)
        {
            var user = await _userRepository.GetUser(userId);

            if (user == null)
            {
                return(new MissionCompletionResult(OperationResultStatus.Error, "User was not found"));
            }
            var currentMission = user.ActiveMissionIds.FirstOrDefault(m => m.MissionId == missionId);

            if (currentMission == null)
            {
                return(new MissionCompletionResult(OperationResultStatus.Error, "Mission was not found"));
            }

            var mission = await _missionRepository.GetMission(missionId);

            //Check if mission is unique and sensored
            var possibleUniqueMissionType = UniqueMissionsDictionary.GetMissionType(missionId);

            if (possibleUniqueMissionType == typeof(Censored))
            {
                return
                    (await
                     UniqueMissionProcessor.Process(
                         possibleUniqueMissionType,
                         new MissionRequest
                {
                    Mission = mission,
                    MissionId = mission.Id,
                    User = user,
                    UserId = user.Id,
                    Status = MissionRequestStatus.AutoApproval,
                    LastUpdateDate = DateTime.UtcNow,
                    Proof = new MissionProof()
                },
                         _missionRequestRepository,
                         _userRepository,
                         _ratingService));
            }

            var oldPoints = user.Points;

            await RewardsCalculator.UpdateUserAfterMissionDecline(
                new MissionRequest { User = user, Mission = mission },
                _missionRepository);

            var userUpdateResult = await _userRepository.UpdateUser(user);

            if (userUpdateResult.Status != OperationResultStatus.Error)
            {
                // new points should always have value
                // ReSharper disable once PossibleInvalidOperationException
                await _ratingService.UpdateUserRating(user, oldPoints, user.Points.Value);
            }
            return(userUpdateResult.Status == OperationResultStatus.Success
                       ? new MissionCompletionResult
            {
                MissionCompletionStatus = MissionCompletionStatus.Fail
            }
                       : MissionCompletionResult.FromOperationResult(userUpdateResult));
        }