Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public IHttpActionResult Post(OrderRegisterCommand orderCmd)
        {
            var validator = orderCmd.Validate();

            if (!validator.IsValid)
            {
                return(HandleValidationFailure(validator.Errors));
            }

            return(HandleCallback(_ordersService.Add(orderCmd)));
        }
Esempio n. 3
0
        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));
            }
        }