コード例 #1
0
        public async Task <IEnumerable <StockSummary> > Get(string type)
        {
            try
            {
                var stockSummaries = await StockSummaryRepository.Get(type);

                if (stockSummaries != null)
                {
                    return(stockSummaries);
                }
                return(null);
            }
            catch (Exception) { throw; }
        }
コード例 #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; }
        }