public async Task <IEnumerable <ProviderCommentsViewModel> > Handle(FindCommentsByProviderQuery request, CancellationToken cancellationToken) { var comments = await _evaluationRepository.Query() .Where(x => x.ProviderId == request.ProviderId) .Select(x => new ProviderCommentsViewModel() { Comment = x.Comment, EvaluationDate = x.EvaluationDate }) .OrderByDescending(x => x.EvaluationDate) .ToListAsync(); return(comments); }
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); }