public async Task <IActionResult> Register([FromForm] InventoryNewViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                return(await resiliencyHelper.ExecuteResilient(async() =>
                {
                    try
                    {
                        var command = new RegisterInventory(Guid.NewGuid(),
                                                            inputModel.Inventory.ProductCode,
                                                            inputModel.Inventory.Description,
                                                            inputModel.Inventory.Quantity,
                                                            inputModel.Inventory.UnitPrice);

                        await inventoryManagementAPI.RegisterInventory(command);
                    }
                    catch (ApiException ex)
                    {
                        if (ex.StatusCode == HttpStatusCode.Conflict)
                        {
                            var content = await ex.GetContentAsAsync <InventoryRuleViolation>();
                            inputModel.Error = content.ErrorMessage;

                            return View("New", inputModel);
                        }
                    }

                    return RedirectToAction("Index");
                }, View("Offline", new InventoryOfflineViewModel())));
            }
            else
            {
                return(View("New", inputModel));
            }
        }
Ejemplo n.º 2
0
 public async Task RegisterInventory(RegisterInventory command)
 {
     await restClient.RegisterInventory(command);
 }