コード例 #1
0
        public static BikePrices[] GetPrices()
        {
            string sql = $"select * from BikePrices";

            BikePrices GetBikePricesFromReader(SqlDataReader reader)
            {
                BikePrices bikePrices = new BikePrices();

                bikePrices.ID = reader["ID"].ToString();

                bikePrices.BikeId = reader["BikeId"].ToString();

                bikePrices.HalfDayWeekend = reader["HalfDayWeekend"].ToString();

                bikePrices.DayWeekend = reader["DayWeekend"].ToString();

                bikePrices.Evening = reader["Evening"].ToString();

                return(bikePrices);
            }

            BikePrices[] pricesValues = GetItems(sql, GetBikePricesFromReader);

            Bike[] bikes = GetBikes();

            foreach (BikePrices price in pricesValues)
            {
                price.BikeName =
                    bikes.Single(bike => bike.Id.ToLower() == price.BikeId.ToLower()).Name;
            }

            List <BikePrices> prices = new List <BikePrices>();

            foreach (Bike bike in bikes)
            {
                BikePrices price = pricesValues.SingleOrDefault(pv => pv.BikeId == bike.Id);

                if (price != null)
                {
                    prices.Add(price);
                }
            }

            InventoryGroup[] inventory = GetInventory();

            BikePrices[] pricesNoInventory
                = prices.Where(p => !inventory.Any(i => i.BikeId == p.BikeId)).ToArray();

            foreach (BikePrices bp in pricesNoInventory)
            {
                prices.Remove(bp);
            }

            return(prices.ToArray());
        }
コード例 #2
0
        public static BillingCost GetPriceEstimateRental
            (string email,
            InventoryGroup[] desiredBikes,
            DateSelection dateSelections)
        {
            double taxPercentage = Convert.ToDouble(GetParameterValue("taxPercentage"));

            BillingCost billingCost = new BillingCost();

            BikePrices[] bikeprices = DatabaseOperations.GetPrices();

            if (dateSelections != null && dateSelections.Date != null)
            {
                bool isWeekend = dateSelections.DateDayOfTheWeek == DayOfWeek.Saturday ||
                                 dateSelections.DateDayOfTheWeek == DayOfWeek.Sunday;

                foreach (InventoryGroup desiredBike in desiredBikes
                         .Where(desiredBike => desiredBike.Wanted > 0))
                {
                    BikePrices[] bikePricesValues
                        = bikeprices.Where(bike => bike.BikeId == desiredBike.BikeId).ToArray();

                    if (bikePricesValues.Count() != 1)
                    {
                        throw new System.Exception("Unable to get bikeprice");
                    }
                    BikePrices bikePrices = bikePricesValues.Single();

                    if (isWeekend == false)
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.Evening.Replace("$", ""));
                    }
                    else if (dateSelections.DayPartEnum == DayPartSelection.DayPart.Day)
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.DayWeekend.Replace("$", ""));
                    }
                    else if (dateSelections.DayPartEnum == DayPartSelection.DayPart.Evening)
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.Evening.Replace("$", ""));
                    }
                    else
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.HalfDayWeekend.Replace("$", ""));
                    }
                }
            }
            billingCost.Price = Math.Round(billingCost.Price, 2);
            billingCost.Tax   = Math.Round(taxPercentage * billingCost.Price, 2);

            billingCost.Discount = GetDiscount(email);

            return(billingCost);
        }
コード例 #3
0
        public static BikePrices[] GetBikePrices()
        {
            string sql = "select * from BikePrices";

            BikePrices GetBikePricesFromReader(SqlDataReader reader)
            {
                BikePrices bikeprices = new BikePrices();

                bikeprices.ID = reader["id"].ToString();

                bikeprices.BikeId = reader["bikeid"].ToString();

                return(bikeprices);
            }

            BikePrices[] bikePrices = GetItems(sql, GetBikePricesFromReader);

            return(bikePrices);
        }