예제 #1
0
        public void Add(InventoryItemViewModel inventoryViewModel)
        {
            InventoryItem inventory = _mapper.Map <InventoryItem>(inventoryViewModel);

            for (int i = 0; i < inventoryViewModel.Quantity; i++)
            {
                _inventoryRepository.Add(new InventoryItem {
                    ProductId             = inventoryViewModel.ProductId,
                    RegistrationDate      = inventoryViewModel.RegistrationDate,
                    InventoryItemStatusId = (int)InventoryItemStatusType.Available
                });
            }

            _inventoryRepository.SaveChanges();
        }
예제 #2
0
        public async Task <Result> Add(InventoryItem inventoryItem)
        {
            try
            {
                var addedInventoryItem = await InventoryItemRepository.Add(inventoryItem);

                if (addedInventoryItem != null)
                {
                    var stockSummary = await StockSummaryRepository.Get(addedInventoryItem.Type, addedInventoryItem.Code, addedInventoryItem.Description);

                    if (stockSummary != null)
                    {
                        stockSummary.Total++;
                        stockSummary = await StockSummaryRepository.Update(stockSummary);

                        if (stockSummary != null)
                        {
                            return new Result
                                   {
                                       Success     = true,
                                       Message     = "Successfully saved to inventory",
                                       Description = $"Item {inventoryItem.Type} {inventoryItem.Code} ({inventoryItem.Description})",
                                       Response    = addedInventoryItem.Id.ToString()
                                   }
                        }
                        ;
                        return(new Result
                        {
                            Success = false,
                            Message = "Failed updating inventory summary",
                            Description = $"Item {inventoryItem.Type} {inventoryItem.Code} ({inventoryItem.Description})"
                        });
                    }
                    stockSummary = await StockSummaryRepository.Add(new StockSummary
                    {
                        Code        = inventoryItem.Code,
                        Description = inventoryItem.Description,
                        Type        = inventoryItem.Type,
                        Total       = 1
                    });

                    if (stockSummary != null)
                    {
                        return new Result
                               {
                                   Success     = true,
                                   Message     = "Successfully saved to inventory",
                                   Description = $"Item {inventoryItem.Type} {inventoryItem.Code} ({inventoryItem.Description})",
                                   Response    = addedInventoryItem.Id.ToString()
                               }
                    }
                    ;
                    return(new Result
                    {
                        Success = false,
                        Message = "Failed saving to inventory summary",
                        Description = $"Item {inventoryItem.Type} {inventoryItem.Code} ({inventoryItem.Description})"
                    });
                }
                return(new Result
                {
                    Success = false,
                    Message = "Failed saving to inventory",
                    Description = $"Item {inventoryItem.Type} {inventoryItem.Code} ({inventoryItem.Description})"
                });
            }
            catch (Exception) { throw; }
        }