public async Task <IActionResult> PutCustomer([FromRoute] int id, [FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Update(int orderId) { using (var db = new PlayContext()) { var order = db.Orders.First(q => q.Id == orderId); order.IsPaid = true; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult Index() { using (var db = new PlayContext()) { var plays = db.Plays.Include("Author").Include("Genre"); var playsIds = plays.Select(p => p.Id); plays.ForEachAsync(p => { db.Entry(p).Collection("Dates").Load(); }).Wait(); ViewBag.Plays = plays.ToList(); } return(View()); }