Ejemplo n.º 1
0
        public IHttpActionResult AddSoldProducts(InvoiceAddProductCommand command)
        {
            var validator = command.Validate();

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

            return(HandleCallback(_invoiceService.AddProduct(command)));
        }
Ejemplo n.º 2
0
        public bool AddProduct(InvoiceAddProductCommand command)
        {
            var invoice = _invoiceRepository.GetById(command.Id);

            if (invoice == null)
            {
                throw new NotFoundException();
            }
            invoice.SoldProducts.Add(
                new SoldProduct
            {
                InvoiceId = command.Id,
                ProductId = command.SoldProduct.ProductId,
                Quantity  = command.SoldProduct.Quantity
            });

            return(_invoiceRepository.Update(invoice));
        }