public async Task SetHighlighted(int pid) { Product p = await _context.Products.FindAsync(pid); p.Highlighted = !p.Highlighted; await _context.SaveChangesAsync(); }
public async Task <bool> DecreaseProductStockAsync(int id, int quant) { var q = await _ctx.Inventory.Where(p => p.ProductId == id).FirstOrDefaultAsync(); if (q == null || (q.Quantity - quant < 0)) { return(false); } q.Quantity -= quant; await _ctx.SaveChangesAsync(); return(true); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Product = await _context.Products.FindAsync(id); if (Product != null) { _context.Products.Remove(Product); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }