private async Task RecalculateRequestTotal(int requestid) { var request = await _context.Requests.FindAsync(requestid); if (request == null) { throw new Exception($"RecalculateRequestTotal: Request not found for id {requestid}"); } request.Total = (from l in _context.Requestlines join p in _context.Products on l.ProductId equals p.Id select new { LineTotal = l.Quantity * p.Price }) .Sum(x => x.LineTotal); request.Status = "MODIFIED"; await _context.SaveChangesAsync(); }
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 <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()); }