コード例 #1
0
ファイル: ArchiveTask.cs プロジェクト: abcwarehouse/nop
 public async System.Threading.Tasks.Task ExecuteAsync()
 {
     using (IDbConnection backendConn = _coreSettings.GetBackendDbConnection())
     {
         await _archiveService.ArchiveProductContentAsync(backendConn);
     }
 }
コード例 #2
0
        public async Task <Dictionary <int, int> > GetStockAsync(int productId)
        {
            Product product = await _productService.GetProductByIdAsync(productId);

            if (product == null)
            {
                return(null);
            }
            string upc = product.Sku;

            if (String.IsNullOrEmpty(upc))
            {
                return(null);
            }

            Dictionary <int, int> branchQuantityDict = new Dictionary <int, int>();

            // go to backend and get quantity
            using (OdbcConnection dbConnection = _settings.GetBackendDbConnection())
            {
                OdbcCommand dbCommand = dbConnection.CreateCommand();

                dbConnection.Open();
                dbCommand.CommandText =
                    "SELECT DISTINCT" +
                    " St." + _backendStockBranch +
                    ", St." + _backendStockQuantity +
                    " FROM " + _backendStockTable + " St" +
                    " LEFT JOIN " + _backendInvTable + " Inv ON St." + _backendStockItemNum + " = Inv." + _backendInvItemNum +
                    " WHERE" +
                    " Inv." + _backendInvModel + " = '" + upc + "';";
                using (OdbcDataReader reader = dbCommand.ExecuteReader())
                {
                    // read in the information
                    while (reader.Read())
                    {
                        string backendBranchId  = reader.GetString(0);
                        var    shopIdEnumerable = _shopAbcRepository.Table
                                                  .Where(s => s.AbcId == backendBranchId)
                                                  .Select(s => s.ShopId);
                        if (shopIdEnumerable.Any() || backendBranchId.Trim().ToLower() == "abc")
                        {
                            int shopId = shopIdEnumerable.First();
                            int backendStockQuantity = reader.GetInt32(1);
                            branchQuantityDict.Add(shopId, backendStockQuantity);
                        }
                        else if (backendBranchId.Trim().ToLower() == "abc")
                        {
                            int backendStockQuantity = reader.GetInt32(1);
                            branchQuantityDict.Add(WAREHOUSE_INT, backendStockQuantity);
                        }
                    }
                }

                dbCommand.Dispose();
                dbConnection.Close();
                // return a list of stock + corresponding shop item
            }
            return(branchQuantityDict);
        }