public async Task <IEnumerable <ClientReviewsRerource> > GetClientReviews() { var id = await GetUserId(); var result = await _repository.GetClientReviewAsync(id); return(_mapper.Map <IEnumerable <ClientReviews>, IEnumerable <ClientReviewsRerource> >(result)); }
public async Task <List <CustomServiceRequestResource> > GetServiceRequestsByServiceProvider() { var serviceRequests = new List <CustomServiceRequestResource>(); var id = await GetServiceProviderId(); var allServiceRequests = await _repository.GetAllServiceRequestsByServiceproviderAsync(id); foreach (var serviceReq in allServiceRequests) { decimal serviceAvgRating = 0; var serviceRatingCounter = 0; decimal clientAvgRatingpoint = 0; var clientRatingCounter = 0; var customServiceReq = new CustomServiceRequestResource(); customServiceReq.Id = serviceReq.Id; customServiceReq.RequestDate = serviceReq.RequestDate; customServiceReq.IsPending = serviceReq.IsPending; customServiceReq.IsApproved = serviceReq.IsApproved; customServiceReq.IsDeleted = serviceReq.IsDeleted; customServiceReq.DeleteDate = serviceReq.DeletedDate; customServiceReq.TotalTime = serviceReq.TotalTime; customServiceReq.OnRide = serviceReq.OnRide; customServiceReq.CheckInStartTime = serviceReq.CheckInStartTime; customServiceReq.ServiceId = serviceReq.ServiceId; customServiceReq.PassengerId = serviceReq.PassengerId; customServiceReq.Service = serviceReq.Service; customServiceReq.ApplicationUser = serviceReq.ApplicationUser; customServiceReq.ServiceReviewComments = new List <string>(); var serviceRatingDetails = await _serviceReviewRepository.GetReviews(serviceReq.ServiceId); var serviceReviews = serviceRatingDetails as ServiceReview[] ?? serviceRatingDetails.ToArray(); if (serviceReviews.Any()) { foreach (var srd in serviceReviews) { customServiceReq.ServiceReviewComments.Add(srd.Comments); serviceAvgRating = serviceAvgRating + srd.RatingPoint; serviceRatingCounter++; } customServiceReq.AvgServiceReview = serviceAvgRating / serviceRatingCounter; } customServiceReq.ClientReviewComments = new List <string>(); var clientRatingDetails = await _clientReviewRepository.GetClientReviewAsync(serviceReq.PassengerId); var clientReviewses = clientRatingDetails as ClientReviews[] ?? clientRatingDetails.ToArray(); if (clientReviewses.Any()) { foreach (var crd in clientReviewses) { customServiceReq.ClientReviewComments.Add(crd.Comments); clientAvgRatingpoint = clientAvgRatingpoint + crd.RatingPoint; clientRatingCounter++; } customServiceReq.AvgClientReview = clientAvgRatingpoint / clientRatingCounter; } serviceRequests.Add(customServiceReq); } return(serviceRequests); }