public async Task <int> GetVehicleRatingAsInteger(long id)
        {
            var ratings = await _repository.GetRatingsByVehicleId(id);

            if (ratings != null && ratings.Count > 0)
            {
                int sum = 0;
                foreach (VehicleRating v in ratings)
                {
                    sum += (int)EnumsUtility.GetStarRatingAsDouble(v.Rate);
                }

                return((int)(sum / ratings.Count));
            }

            return(0);
        }
Ejemplo n.º 2
0
        public async Task <double> GetAverageFlightRating(long id)
        {
            var ratings = await _avioRepository.GetFlightRatingsByCompanyId(id);

            if (ratings == null)
            {
                return(0.0);
            }
            if (ratings.Count == 0)
            {
                return(0.0);
            }

            double sum = 0;

            foreach (FlightRating r in ratings)
            {
                sum += EnumsUtility.GetStarRatingAsDouble(r.Rate);
            }

            return(sum / ratings.Count);
        }
Ejemplo n.º 3
0
        public async Task <Double> GetCompanyRatingAsDouble(long id)
        {
            var ratings = await _rentACarRepository.GetCompanyRatingsByCompanyId(id);

            if (ratings == null)
            {
                return(0);
            }
            if (ratings.Count == 0)
            {
                return(0);
            }

            double sum = 0;

            foreach (CarCompanyRating r in ratings)
            {
                sum += EnumsUtility.GetStarRatingAsDouble(r.Rate);
            }

            return(sum / ratings.Count);
        }