public async Task <IActionResult> UseInventoryItem(string productCode, UseInventoryItem 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 InventoryUsed ToModel(this UseInventoryItem command, DateTime dateTime, double totalPrice = 0)
 {
     return new InventoryUsed(
         command.MessageId,
         command.ProductCode,
         command.JobId,
         command.Quantity,
         totalPrice,
         dateTime);
 }
 public static InventoryItemUsed ToEvent(this UseInventoryItem command)
 {
     return(new InventoryItemUsed()
     {
         JobId = command.JobId,
         Quantity = command.Quantity,
         ProductCode = command.ProductCode,
         Price = 0
     });
 }
Beispiel #4
0
        public static void UseInventoryQuantityMustBeSmallerOrEqualToInventoryLevel(this UseInventoryItem useInventoryItem, Inventory inventory)
        {
            if (inventory == null)
            {
                throw new InventoryRuleViolationException("Product does not exist");
            }

            if (useInventoryItem.Quantity > inventory.Quantity)
            {
                throw new InventoryRuleViolationException("Not able to use item, not enough in stock");
            }
        }
 public static InventoryUsed ToModel(this UseInventoryItem command, double totalPrice = 0)
 {
     return ToModel(command, DateTime.Now, totalPrice);
 }
Beispiel #6
0
 public async Task UseInventoryItem(string productCode, UseInventoryItem command)
 {
     await restClient.UseInventoryItem(productCode, command);
 }