public async Task UpdateInventory(UpdateInventoryCommand command, CancellationToken token)
        {
            var target = await GetInventoryById(command.InventoryId, token).ConfigureAwait(false);

            target.Name = command.Name.Trim().ToUpperInvariant();

            _db.Entry(target).State = EntityState.Modified;
        }
        public async Task <ActionResult <InventoryApiModel> > UpdateInventory([FromBody] UpdateInventoryCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);

                return(CreatedAtRoute("InventoryById",
                                      new { id = command.InventoryId }, result));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new { ErrorMessage = ex.Message }));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateInventoryAsync(string id, UpdateInventoryCommand updateCommand)
        {
            if (string.IsNullOrEmpty(updateCommand.ProductId))
            {
                updateCommand.ProductId = id;
            }

            var result = await _updateInventoryHandler.HandleAsync(updateCommand);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(Ok());
        }
Esempio n. 4
0
        public IHttpActionResult Update(StockUpdateViewModel updateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            UpdateInventoryCommand command = UpdateInventoryCommand.Create(updateModel.Name, updateModel.System, updateModel.Goods.Select(g => new Dto.InventoryItem()
            {
                Buy       = g.Buy,
                Category  = g.Category,
                Sell      = g.Sell,
                Commodity = g.Name
            }).ToArray());

            _Bus.Publish(command);

            return(Ok(command.Id));
        }
Esempio n. 5
0
        public async Task <ICommandResult> HandleAsync(UpdateInventoryCommand command)
        {
            command.Validate();

            if (!command.IsValid)
            {
                return(new CommandResult(false, command.Errors));
            }

            var product = await _productRepository.GetAsync(command.ProductId);

            if (product is null)
            {
                return(new CommandResult(false, "Product not found"));
            }

            product.UpdateInventory(command.Count, command.MinCount);

            await _productRepository.UpdateInventoryAsync(product.Inventory);

            return(new CommandResult(true, "Inventory successfully updated."));
        }
Esempio n. 6
0
 public ICommandResult Handle(UpdateInventoryCommand command)
 {
     throw new NotImplementedException();
 }
Esempio n. 7
0
 public AddInventoryViewModel(Store store)
 {
     this.store             = store;
     UpdateInventoryCommand = new UpdateInventoryCommand(this);
     products = store.GetAllProducts();
 }