public async Task <IActionResult> CreateRateAsync(int id, [FromBody] CreateRate command)
        {
            var recipe = await _recipeService.GetAsync(id);

            var rate = await _rateService.CreateAsync(command, recipe);

            var rateDto = _mapper.Map <RateDto>(rate);

            return(Created($"{Request.Host}{Request.Path}/{rate.Id}", rateDto));
        }
        public async Task <Rate> CreateAsync(CreateRate command, Recipe recipe)
        {
            var rate = new Rate(command.Value, command.Description);
            await _context.Rates.AddAsync(rate);

            recipe.Rates.Add(rate);

            await _context.SaveChangesAsync();

            return(rate);
        }
        public async Task <IActionResult> CreateRate(CreateRate createRate)
        {
            var reservation = context.ReservationCar.Find(createRate.id);

            if (reservation != null)
            {
                var carId = reservation.IdCar;

                var cc = context.Cars.Include(x => x.CarCompany).ToList().SingleOrDefault(x => x.Id == carId).CarCompany;

                var car = context.Cars.Find(carId);

                var companyId = cc.Id;

                Rating ratingCompany = new Rating();


                ratingCompany.IdService     = companyId.ToString();
                ratingCompany.Mark          = Int32.Parse(createRate.serviceRating);
                ratingCompany.Descriminator = ServiceType.Company;


                context.Rating.Add(ratingCompany);

                await context.SaveChangesAsync();

                ProsecnaOcena(companyId.ToString(), createRate.serviceRating, cc);

                Rating ratingCar = new Rating();
                ratingCar.IdService     = carId;
                ratingCar.Mark          = Int32.Parse(createRate.vehicleRating);
                ratingCar.Descriminator = ServiceType.Car;

                context.Rating.Add(ratingCar);
                await context.SaveChangesAsync();

                ProsecnaOcena(carId, createRate.vehicleRating, car);
            }

            else
            {
                var reservationF = context.FlightReservations.Find(Int32.Parse(createRate.id));

                if (reservationF != null)
                {
                    var    let           = reservationF.FlightId;
                    var    Let           = context.Flights.Find(let);
                    var    company       = context.Aircompanies.Include(x => x.Flights).SingleOrDefault(x => x.Flights.Any(x => x.Id == reservationF.FlightId));
                    Rating ratingCompany = new Rating();


                    ratingCompany.IdService     = company.Id.ToString();
                    ratingCompany.Mark          = Int32.Parse(createRate.serviceRating);
                    ratingCompany.Descriminator = ServiceType.Company;


                    context.Rating.Add(ratingCompany);

                    await context.SaveChangesAsync();

                    ProsecnaOcena(company.Id.ToString(), createRate.serviceRating, company);

                    Rating ratingFlight = new Rating();
                    ratingFlight.IdService     = let.ToString();
                    ratingFlight.Mark          = Int32.Parse(createRate.vehicleRating);
                    ratingFlight.Descriminator = ServiceType.Flight;

                    context.Rating.Add(ratingFlight);
                    await context.SaveChangesAsync();


                    ProsecnaOcena(let.ToString(), createRate.vehicleRating, Let);
                }
            }

            return(Ok());
        }