public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(DeskQuote).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeskQuoteExists(DeskQuote.DeskQuoteId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
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")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } DeskQuote newQuote = DeskQuote; //calculate a surfacearea decimal surfaceArea = DeskQuote.Desk.Depth * DeskQuote.Desk.Width; //declare a variable decimal surfaceAreaPrice = 0; if (surfaceArea > 1000) { surfaceAreaPrice = (surfaceArea - 1000) * 1; } //new var var surfaceMaterialPrice = 0; surfaceMaterialPrice = _context.SurfaceMaterial .Where(r => r.SurfaceMaterialId == DeskQuote.Desk.SurfaceMaterialId) .Select(r => r.SurfaceMaterialId) .FirstOrDefault(); //here I wrote a switch statement, because our price is based on materia var DrawersPrice = DeskQuote.Desk.NumberOfDrawers * 50; decimal shippingPrice = 0; if (surfaceArea < 1000) { shippingPrice = _context.RushOrder .Where(r => r.RushOrderId == DeskQuote.RushOrderId) .Select(r => r.PriceLessThan1000) .FirstOrDefault(); } else if (surfaceArea < 2000) { shippingPrice = _context.RushOrder .Where(r => r.RushOrderId == DeskQuote.RushOrderId) .Select(r => r.Price1000To2000) .FirstOrDefault(); } else { shippingPrice = _context.RushOrder .Where(r => r.RushOrderId == DeskQuote.RushOrderId) .Select(r => r.PriceGreater2000) .FirstOrDefault(); } DeskQuote.QuotePrice = 200 + surfaceAreaPrice + DrawersPrice + surfaceMaterialPrice + shippingPrice; _context.DeskQuote.Add(DeskQuote); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }