Ejemplo n.º 1
0
 public static void InventoryProductCodeLengthShouldBe12CharactersLong(this RegisterInventory registerInventory)
 {
     if (registerInventory.ProductCode.Length != 12)
     {
         throw new InventoryRuleViolationException("Inventory ProductCode should be 12 characters long.");
     }
 }
Ejemplo n.º 2
0
 public static void InventoryQuantityShouldBeZeroOrLarger(this RegisterInventory registerInventory)
 {
     if (registerInventory.Quantity < 0)
     {
         throw new InventoryRuleViolationException("Quantity should be larger than 0.");
     }
 }
Ejemplo n.º 3
0
 public static void InventoryPriceShouldBeZerorOrLarger(this RegisterInventory registerInventory)
 {
     if (registerInventory.UnitPrice < 0)
     {
         throw new InventoryRuleViolationException("UnitPrice should be larger than 0.");
     }
 }
        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));
            }
        }
        public async Task <IActionResult> RegisterInventory(RegisterInventory command)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await commandExecutor.RunAsync(command);

                    return(Ok());
                }
                return(BadRequest());
            }
            catch (InventoryRuleViolationException ex)
            {
                return(StatusCode(StatusCodes.Status409Conflict, new InventoryRuleViolation(ex.Message)));
            }
            catch (Exception ex)
            {
                string errorMessage = "Unable to save changes. " +
                                      "Try again, and if the problem persists " +
                                      "see your system administrator.";
                Log.Error(ex, errorMessage);
                ModelState.AddModelError("ErrorMessage", errorMessage);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
 public static Inventory ToModel(this RegisterInventory command)
 {
     return new Inventory(
         command.ProductCode,
         command.Description,
         command.Quantity,
         command.UnitPrice);
 }
 public static InventoryRegistered ToEvent(this RegisterInventory command)
 {
     return(new InventoryRegistered()
     {
         ProductCode = command.ProductCode,
         Description = command.Description,
         Quantity = command.Quantity,
         UnitPrice = command.UnitPrice
     });
 }
Ejemplo n.º 8
0
 public async Task RegisterInventory(RegisterInventory command)
 {
     await restClient.RegisterInventory(command);
 }