public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MegaDeskWebContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MegaDeskWebContext> >()))
            {
                if (context.Desktop.Any())
                {
                    return;   // DB has been seeded
                }

                context.Desktop.AddRange(
                    new Desktop
                {
                    Cost = 200,
                    Type = "Oak"
                },
                    new Desktop
                {
                    Cost = 100,
                    Type = "Laminate"
                },
                    new Desktop
                {
                    Cost = 50,
                    Type = "Pine"
                },

                    new Desktop
                {
                    Cost = 300,
                    Type = "Rosewood"
                },

                    new Desktop
                {
                    Cost = 125,
                    Type = "Veneer"
                }

                    );
                context.SaveChanges();
            }
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MegaDeskWebContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MegaDeskWebContext> >()))
            {
                if (context.Shipping.Any())
                {
                    return;   // DB has been seeded
                }

                context.Shipping.AddRange(
                    new Shipping
                {
                    Type      = "3-Day",
                    CostSmall = 60.0f,
                    CostMed   = 70.0f,
                    CostLarge = 80.0f
                },
                    new Shipping
                {
                    Type      = "5-Day",
                    CostSmall = 40.0f,
                    CostMed   = 50.0f,
                    CostLarge = 60.0f
                },
                    new Shipping
                {
                    Type      = "7-Day",
                    CostSmall = 30.0f,
                    CostMed   = 35.0f,
                    CostLarge = 40.0f
                },
                    new Shipping
                {
                    Type      = "14-Day",
                    CostSmall = 0.0f,
                    CostMed   = 0.0f,
                    CostLarge = 0.0f
                });
                context.SaveChanges();
            }
        }
Exemple #3
0
 public CreateModel(MegaDeskWebContext context)
 {
     _context = context;
 }
Exemple #4
0
        public decimal getQuotePrice(MegaDeskWebContext context) //DeskQuote deskQuote
        {
            _context = context;

            //Sets base price to order
            decimal total = BASE_DESK_PRICE;

            //Get the surface area
            decimal surfaceArea = this.Desk.Width * this.Desk.Depth;

            //Initializes the surface area price
            decimal surfaceAreaPrice = 0M;

            //Add the price of the table if it is a certain size
            if (surfaceArea > 1000)
            {
                surfaceAreaPrice = (surfaceArea - 1000) * PRICE_PER_INCH;
            }

            //Add to the total
            total += surfaceAreaPrice;

            //Get price for the drawers
            decimal numberOfDrawersPrice = this.Desk.NumberOfDrawers * DRAWER_COST;

            //Add to the total
            total += numberOfDrawersPrice;



            //Calculate shipping price pulling from database

            var shippingOptions = from m in _context.Shipping
                                  select m;


            //Initialize shipping cost with default value
            decimal shippingCost = 0;


            shippingOptions = shippingOptions.Where(s => s.ShippingId == this.ShippingId);

            var shipping = shippingOptions.FirstOrDefault();

            if (surfaceArea < 1000)
            {
                shippingCost = shipping.Under1000;
            }
            else if (surfaceArea > 1000 && surfaceArea < 2000)
            {
                shippingCost = shipping.Between1000And2000;
            }
            else if (surfaceArea > 2000)
            {
                shippingCost = shipping.Over2000;
            }

            //Add to the total
            total += shippingCost;

            //Calculate the surface material price pulling from database
            var surfaceMaterialOptions = from m in _context.SurfaceMaterial
                                         select m;
            //There isn't a default value for this variable
            decimal surfaceMaterialCost;


            surfaceMaterialOptions = surfaceMaterialOptions.Where(s => s.SurfaceMaterialId == this.Desk.SurfaceMaterialId);

            var material = surfaceMaterialOptions.FirstOrDefault();

            surfaceMaterialCost = material.Cost;

            //Add to the total
            total += surfaceMaterialCost;

            //Calculate the final price of the order
            //TO-DO
            return(total);
        }
        public static DeskQuote PopulateQuote(DeskQuote incompleteQuote, int shipSelector, int material, MegaDeskWebContext context)
        {
            incompleteQuote.Desk.SurfaceMaterial   = context.SurfaceMaterial.Where(s => s.SurfaceMaterialID == material).FirstOrDefault();
            incompleteQuote.Desk.SurfaceMaterialID = material;
            decimal surfaceArea = incompleteQuote.Desk.Width * incompleteQuote.Desk.Depth;
            decimal price       = 200;

            incompleteQuote.QuoteDate = DateTime.Now;
            // add surfacematerial price


            price += incompleteQuote.Desk.SurfaceMaterial.SurfaceMaterialPrice;
            // add drawer price
            price += incompleteQuote.Desk.NumDrawers * 50;
            // add additional material price
            if (surfaceArea > 1000)
            {
                price += surfaceArea - 1000;
            }

            // populate RushShipping field.
            switch (shipSelector)
            {
            case 3:
                if (surfaceArea <= 1000)
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Three-Day Small").SingleOrDefault();
                }
                else if (surfaceArea < 2000)
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Three-Day Medium").SingleOrDefault();
                }
                else
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Three-Day Large").SingleOrDefault();
                }
                break;

            case 5:
                if (surfaceArea <= 1000)
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Five-Day Small").SingleOrDefault();
                }
                else if (surfaceArea < 2000)
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Five-Day Medium").SingleOrDefault();
                }
                else
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Five-Day Large").SingleOrDefault();
                }
                break;

            case 7:
                if (surfaceArea <= 1000)
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Seven-Day Small").SingleOrDefault();
                }
                else if (surfaceArea < 2000)
                {
                    incompleteQuote.RushShipping = context.RushShipping.Where(p => p.RushShippingName == "Seven-Day Medium").SingleOrDefault();
                }
                else
                {
                    incompleteQuote.RushShipping = (RushShipping)context.RushShipping.Where(p => p.RushShippingName == "Seven-Day Large");
                }
                break;

            default:
            {
                incompleteQuote.RushShipping = new RushShipping {
                    RushShippingID = 0, RushShippingName = "standard", RushShippingPrice = 0
                };
                break;
            }
            }
            price += incompleteQuote.RushShipping.RushShippingPrice;
            incompleteQuote.Price = price;
            DeskQuote completeQuote = incompleteQuote;

            return(completeQuote);
        }