public IHttpActionResult PutPurchase(int id, Purchase purchase) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchase.Id) { return(BadRequest()); } db.Entry(purchase).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PurchaseExists(id)) { return(NotFound()); } else { throw; } } return(Ok(purchase)); }
public async Task <int> DeleteByID(int purchaseID) { using (var context = new PurchaseTrackerContext()) { var purchase = await context.Purchase.FindAsync(purchaseID); context.Entry(purchase).State = EntityState.Deleted; return(await context.SaveChangesAsync()); } }
public async Task <int> UpdatePurchase(Purchase purchase) { using (var context = new PurchaseTrackerContext()) { var updatePurchase = await context.Purchase.FindAsync(purchase.PurchaseId); context.Entry(updatePurchase).CurrentValues.SetValues(purchase); return(await context.SaveChangesAsync()); } }