public async Task <Order> AddOrderAsync(Order order) { var orderResult = await _orderContext.AddAsync(order); await _orderContext.SaveChangesAsync(); return(orderResult.Entity); }
public async Task <TEntity> AddAsync(TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null"); } try { await _orderContext.AddAsync(entity); await _orderContext.SaveChangesAsync(); return(entity); } catch (Exception) { throw new Exception($"{nameof(entity)} could not be saved"); } }
public async Task <CreateOrderResponse> Handle(CreateOrderRequest request, CancellationToken cancellationToken) { await _validator.ValidateAndThrowAsync(request.Order, cancellationToken); OrderEntity orderEntity = _mapper.Map <OrderEntity>(request.Order); await _dbContext.AddAsync(orderEntity, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); await RaiseOrderCreatedEvent(orderEntity, cancellationToken); return(new CreateOrderResponse { OrderId = orderEntity.OrderId }); }