示例#1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.


        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }



            //Save Desk and then save DeskQuote
            //Adds desk
            _context.Desk.Add(Desk);
            await _context.SaveChangesAsync();

            //Set desk Id
            DeskQuote.DeskId = Desk.DeskId;

            //Set desk
            DeskQuote.Desk = Desk;

            //Set quote date
            DeskQuote.CurrentDate = DateTime.Now;


            //Add CalculatePrice method; sets the quote price
            DeskQuote.Price = DeskQuote.GetQuote(_context);

            //Adds and saves the desk quote
            _context.DeskQuote.Add(DeskQuote);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            // add desk
            _context.Desk.Add(Desk);
            await _context.SaveChangesAsync();

            // set Quote Date
            DeskQuote.QuoteDate = DateTime.Now;

            // set deskid
            DeskQuote.DeskId = Desk.DeskId;

            // set desk
            DeskQuote.Desk = Desk;

            // set quote Price
            DeskQuote.QuotePrice = DeskQuote.GetQuotePrice(_context);

            DeskQuote.DeliveryId = DeskQuote.Delivery.DeliveryId;
            DeskQuote.Delivery   = null;
            // DeskQuote.QuotePrice = DeskQuote.GetQuotePrice(_context);

            _context.DeskQuote.Add(DeskQuote);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //add desk
            _context.Desk.Add(Desk);
            await _context.SaveChangesAsync();

            //set desk id
            DeskQuote.DeskId = Desk.DeskId;

            //set desk
            DeskQuote.Desk = Desk;

            //set quote date
            DeskQuote.QuoteDate = DateTime.Today;

            DeskQuote.Shipping             = DeskQuote.Shipping;
            DeskQuote.Desk.SurfaceMaterial = Desk.SurfaceMaterial;
            //set quote price
            DeskQuote.QuotePrice = DeskQuote.GetQuotePrice(_context);

            //set deskqoute
            _context.DeskQuote.Add(DeskQuote);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
                //return await this.OnGetAsync(this.id);

                //return RedirectToPage("./DeskQuotes/Edit");
            }


            //DeskQuote.Price = DeskQuote.GetQuote(_context);
            _context.Attach(DeskQuote).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeskQuoteExists(DeskQuote.DeskQuoteId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }


            return(RedirectToPage("./Index"));
        }
示例#5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Desk).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeskExists(Desk.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            DeskQuote = await _context.DeskQuote.FindAsync(id);

            if (DeskQuote != null)
            {
                _context.DeskQuote.Remove(DeskQuote);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#7
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(DeskQuote).State = EntityState.Modified;

            try
            {
                var QuoteFromDB = await _context.DeskQuote.FindAsync(DeskQuote.DeskQuoteId);

                var DeskFromDB = await _context.Desk.FindAsync(DeskQuote.DeskId);

                DeskFromDB = Desk;
                //set desk
                QuoteFromDB.Desk = DeskFromDB;

                QuoteFromDB.QuoteDate = DateTime.Today;

                //set quote price
                QuoteFromDB.QuotePrice = DeskQuote.GetQuotePrice(_context);
                QuoteFromDB            = DeskQuote;

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeskQuoteExists(DeskQuote.DeskQuoteId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#8
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //get current date for date
            Desk.DateAdded = DateTime.Today;

            //add the bace things for calc
            var materials = 0;;
            var orderRush = 0;
            var basePrice = 200;
            var material  = Request.Form["surfaceMaterial"];


            // Calc the area and drawer price
            var area    = Desk.width * Desk.depth;
            var drawers = Desk.numberOfDrawers * 50;


            // Materials calc
            if (material == "Laminate")
            {
                materials = 100;
            }
            else if (material == "Oak")
            {
                materials = 200;
            }
            else if (material == "Pine")
            {
                materials = 50;
            }
            else if (material == "Rosewood")
            {
                materials = 300;
            }
            else if (material == "Veneer")
            {
                materials = 125;
            }


            // rush level calc
            int rushLevel = Convert.ToInt32(Desk.rushOrder);

            if (rushLevel == 3 && area < 1000)
            {
                orderRush = 60;
            }
            else if (rushLevel == 5 && area < 1000)
            {
                orderRush = 40;
            }
            else if (rushLevel == 7 && area < 1000)
            {
                orderRush = 30;
            }

            if (rushLevel == 3 && (area >= 1000 && area <= 2000))
            {
                orderRush = 70;
            }
            else if (rushLevel == 5 && (area >= 1000 && area <= 2000))
            {
                orderRush = 50;
            }
            else if (rushLevel == 7 && (area >= 1000 && area <= 2000))
            {
                orderRush = 35;
            }

            if (rushLevel == 3 && area > 2000)
            {
                orderRush = 80;
            }
            else if (rushLevel == 5 && area > 2000)
            {
                orderRush = 60;
            }
            else if (rushLevel == 7 && area > 2000)
            {
                orderRush = 40;
            }

            //Calc the final price
            Desk.price = Convert.ToDecimal(basePrice + area + drawers + materials + orderRush);

            //send desk to the database
            _context.Desk.Add(Desk);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }