public int Add(OrderRegisterCommand orderCmd) { var order = Mapper.Map <OrderRegisterCommand, Order>(orderCmd); // obtém a entidade do banco order.Product = _repositoryProduct.GetById(orderCmd.ProductId) ?? throw new NotFoundException(); var neworder = _repositoryOrder.Add(order); return(neworder.Id); }
public IHttpActionResult Post(OrderRegisterCommand orderCmd) { var validator = orderCmd.Validate(); if (!validator.IsValid) { return(HandleValidationFailure(validator.Errors)); } return(HandleCallback(_ordersService.Add(orderCmd))); }
public OrderRegisterResult Register(OrderRegisterCommand command) { using (var transaction = new TransactionScope()) { var order = orderFactory.Create(command.orderNumber, command.orderDate, command.address, command.items); orderRepository.Save(order); transaction.Complete(); return(new OrderRegisterResult(order.Id)); } }