public async Task <IActionResult> PutProduct(int id, Product product) { if (id != product.Id) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutVendor(int id, Vendor vendor) { if (id != vendor.Id) { return(BadRequest()); } _context.Entry(vendor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VendorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Request> > SetToReview(Request request) { if (request == null) { return(NoContent()); } request.Status = (request.Total <= 50) ? "APPROVED" : "REVIEW"; _context.Entry(request).State = EntityState.Modified; await _context.SaveChangesAsync(); return(request); }
private async Task RecalculateTotal(int requestId) { var request = await _context.Request.FindAsync(requestId); var requestLines = await _context.Requestline.Where(r => r.RequestId == requestId).ToListAsync(); decimal total = 0; foreach (var item in requestLines) { total += item.Quantity * item.Product.Price; } request.Total = total; await _context.SaveChangesAsync(); }