public async Task <CustomerDto> Handle(AddCustomerCommand request, CancellationToken cancellationToken) { var customer = new Customer { Name = request.Name }; await _foodDbContext.AddAsync(customer); return(new CustomerDto { Name = customer.Name, CustomerId = customer.Id }); }
public async Task <TEntity> AddAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null"); } try { await _repositoryFoodDbContext.AddAsync(entity); await _repositoryFoodDbContext.SaveChangesAsync(); return(entity); } catch (Exception) { throw new Exception($"{nameof(entity)} could not be saved"); } }