public async Task <Customer> AddCustomerAsync(Customer customer) { var customerResult = await _customerContext.AddAsync(customer); await _customerContext.SaveChangesAsync(); return(customerResult.Entity); }
public async Task<TEntity> AddAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null"); } try { await CustomerContext.AddAsync(entity); await CustomerContext.SaveChangesAsync(); return entity; } catch (Exception ex) { throw new Exception($"{nameof(entity)} could not be saved: {ex.Message}"); } }
public async Task <IActionResult> Post(Customer model) { try { await _ctx.AddAsync(model); if (await _ctx.SaveChangesAsync() > 0) { var url = _generator.GetPathByRouteValues("GetCustomer", new { id = model.Id }); return(Created(url, model)); } else { return(BadRequest("Failed to create customer")); } } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <TEntity> AddAsync(TEntity entity) { if (entity == null) { throw new ArgumentException($"{nameof(AddAsync)} entity must not be null"); } try { await customerContext.AddAsync(entity); await customerContext.SaveChangesAsync(); // we returned entity that was be saved previously return(entity); } catch (Exception ex) { throw new Exception($"{nameof(entity)} couldn't be saved: {ex.Message}"); } }
public async Task AddItemAsync(Customer item) { await _context.AddAsync(item).ConfigureAwait(false); }