public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(Products.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Products.Add(Products); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Sales = await _context.Sales.FindAsync(id); if (Sales != null) { _context.Sales.Remove(Sales); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // Calculate the total Value of the Sale var product = _context.Products.Find(Sales.ProductId); this.Sales.TotalPrice = product.Price * Sales.Quantity.Value; _context.Sales.Add(Sales); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }