public async Task <IActionResult> PutProduct(long 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> PutCustomer(long id, Customer customer) { 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 virtual async Task <int> AddAsync(TEntity obj) { if (obj != null) { DbSet.Add(obj); return(await DbContext.SaveChangesAsync()); } else { throw new ArgumentNullException(); } }
public async Task <ActionResult <Customer> > Post(Customer newCustomer) { newCustomer.id = Guid.NewGuid(); _context.Customers.Add(newCustomer); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetAll), newCustomer)); }
public async Task <IActionResult> PutOrder(long id, Order order) { var originalOrder = _context.Orders .Where(o => o.Id == id) .Include(o => o.Rows) .SingleOrDefault(); originalOrder.Rows.ToList().ForEach(r => _context.Entry(r).State = EntityState.Deleted); await _context.SaveChangesAsync(); foreach (var orderRow in order.Rows) { orderRow.Id = 0; _context.OrderRows.Add(orderRow); } await _context.SaveChangesAsync(); _context.Entry(originalOrder).CurrentValues.SetValues(order); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task CommitAsync() { await _db.SaveChangesAsync(); }