public ICommandResult Handle(IncrementMerchandiseStockCommand command)
        {
            var    merchandise  = _repository.GetByBookId(command.BookId);
            string message      = "Falha no incremento do estoque verifique o preço de venda pois pode estar inadequado";
            bool   insertStatus = true;

            if (merchandise == null)
            {
                merchandise      = new StockMerchandise();
                merchandise.Book = command.Book;

                insertStatus = merchandise.Increment(command.Price, command.Quantity, command.PriceSeller);

                if (insertStatus)
                {
                    _repository.CreateMerchandise(merchandise);
                    message = "Estoque de mercadoria criado com sucesso";
                }
            }
            else
            {
                insertStatus = merchandise.Increment(command.Price, command.Quantity, command.PriceSeller);

                if (insertStatus)
                {
                    _repository.UpdateMerchandise(merchandise);
                    message = "Estoque de mercadoria incrementado com sucesso";
                }
            }

            _repository.SaveChanges();
            return(new GenericCommandResult(insertStatus, message, merchandise));
        }
예제 #2
0
 public IHttpActionResult PostMerchandise(Merchandise merchandise)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     merchandiseRepository.CreateMerchandise(merchandise);
     return(CreatedAtRoute("DefaultApi", new { id = merchandise.ID }, merchandise));
 }