예제 #1
0
        public async Task <IEnumerable <SpecialOffer> > GetAllSpecialOffers(int enterpriseId)
        {
            try
            {
                var temp = await repo.GetAllSpecialOffers(enterpriseId);

                return(temp);
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
        public async Task <CarReservation> CreateReservation(ReservationParameters paramss)
        {
            var enterprise = await repo2.GetOneEnterprise(paramss.EnterpriseId);

            var car = await repo.GetOneCar(paramss.EnterpriseId, paramss.CarId);

            var specialOfferss = await repo3.GetAllSpecialOffers(paramss.EnterpriseId);


            int numberOfDays = (paramss.DateTo - paramss.DateFrom).Days + 1;

            int price = numberOfDays * car.Price;

            CarReservation retValue = new CarReservation();

            retValue.IsRated            = false;
            retValue.NumberOfDays       = numberOfDays;
            retValue.SelectedCar        = car;
            retValue.SelectedEnterprise = enterprise;
            retValue.DateFrom           = paramss.DateFrom;
            retValue.DateTo             = paramss.DateTo;
            retValue.RentedDay          = paramss.RentedDay;
            List <SpecialOffer> specialOffers = specialOfferss.OrderBy(i => i.NumberOfDays).ToList();

            for (int i = 0; i < specialOffers.Count() - 2; i++)
            {
                if (numberOfDays == specialOffers[i].NumberOfDays)
                {
                    retValue.RealizedPackage = specialOffers[i];
                }

                for (int j = i + 1; j <= specialOffers.Count() - 1; j++)
                {
                    if (numberOfDays > specialOffers[i].NumberOfDays && numberOfDays < specialOffers[j].NumberOfDays)
                    {
                        retValue.RealizedPackage = specialOffers[i];
                    }

                    else if (numberOfDays == specialOffers[j].NumberOfDays)
                    {
                        retValue.RealizedPackage = specialOffers[j];
                    }

                    else if (numberOfDays > specialOffers[i].NumberOfDays && numberOfDays >= specialOffers[j].NumberOfDays)
                    {
                        retValue.RealizedPackage = specialOffers[j];
                    }
                }
            }

            if (retValue.RealizedPackage != null)
            {
                price          = price - ((price * retValue.RealizedPackage.Discount) / 100);
                retValue.Price = price;
            }
            else
            {
                retValue.Price = price;
            }


            return(retValue);
        }