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 PutMerchandise(int id, Merchandise merchandise)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != merchandise.ID)
     {
         return(BadRequest());
     }
     try
     {
         merchandiseRepository.UpdateMerchandise(merchandise);
         return(StatusCode(HttpStatusCode.NoContent));
     }
     catch (DbUpdateConcurrencyException)
     {
         if (merchandiseRepository.GetMerchandiseByID(id) != null)
         {
             return(Conflict());
         }
         else
         {
             throw;
         }
     }
 }