public async Task <bool> Handle(FinishSolicitationCommand request, CancellationToken cancellationToken)
        {
            var solicitation = await _solicitationRepository.FindById(request.Id);

            if (solicitation == null)
            {
                _notificationContext.BadRequest(nameof(Messages.ObjectNotExists), Messages.ObjectNotExists.FormatValues("Solicitação"));
                return(false);
            }
            solicitation.Status = SolicitationStatus.Finished;

            await _solicitationRepository.Update(solicitation);

            if (request.SpeedGrade.HasValue && request.ExperienceGrade.HasValue && request.EfficiencyGrade.HasValue)
            {
                var evaluation = new SolicitationEvaluation()
                {
                    Id              = Guid.NewGuid(),
                    SolicitationId  = solicitation.Id,
                    ClientId        = solicitation.ClientId,
                    ProviderId      = solicitation.ProviderId,
                    Comment         = request.Comment,
                    EfficiencyGrade = request.EfficiencyGrade.Value,
                    ExperienceGrade = request.ExperienceGrade.Value,
                    SpeedGrade      = request.SpeedGrade.Value,
                    EvaluationDate  = DateTime.Now
                };

                await _solicitationEvaluationRepository.Add(evaluation);

                var evaluationsOfProvider = (from evalt in _solicitationEvaluationRepository.Query().Concat(new SolicitationEvaluation[] { evaluation })
                                             where evalt.ProviderId == evaluation.ProviderId
                                             group evalt by evalt.ProviderId into grp
                                             select new
                {
                    ProviderId = grp.Key,
                    Rate = grp.Average(x => (x.SpeedGrade + x.ExperienceGrade + x.EfficiencyGrade) / 3)
                }).Single();

                var provider = await _contractingUserRepository.FindById(solicitation.ProviderId);

                provider.CurrentRating = evaluationsOfProvider.Rate;

                await _contractingUserRepository.Update(provider);
            }

            return(true);
        }
示例#2
0
        public async Task <bool> Handle(UpdateSearchRadiusCommand request, CancellationToken cancellationToken)
        {
            var user = await _contractingUserRepository.FindById(request.UserId);

            if (user == null)
            {
                _notificationContext.BadRequest(nameof(Messages.ObjectNotExists), Messages.ObjectNotExists.FormatValues("Usuário"));
                return(false);
            }

            user.KiloMetersSearchRadius = request.KiloMetersSearchRadius;

            await _contractingUserRepository.Update(user);

            return(true);
        }
示例#3
0
        public async Task <long> Handle(FindSearchRadiusByContractingUserQuery request, CancellationToken cancellationToken)
        {
            var user = await _userRepository.FindById(request.UserId);

            return(user.KiloMetersSearchRadius);
        }