コード例 #1
0
        public bool UpdateProductStockAmount(string productNumber, int productAmount)
        {
            try
            {
                StockEntityModel.ProductStock productStock = ParseProductStockDataToProductStock(RetrieveProductStock(productNumber));
                if (productStock == null)
                {
                    return(false);
                }
                else
                {
                    productStock.Amount += productAmount;
                }

                using (StockProvider database = new StockProvider())
                {
                    var context = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)database).ObjectContext;
                    context.ExecuteStoreCommand("UPDATE ProductStocks SET Amount= {0} WHERE Number= {1}", productStock.Amount, productNumber);
                    database.SaveChanges();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
 private StockEntityModel.ProductStock ParseProductStockDataToProductStock(ProductStockData productStockData)
 {
     StockEntityModel.ProductStock productStock = new StockEntityModel.ProductStock()
     {
         Number      = productStockData.Number,
         Name        = productStockData.Name,
         Description = productStockData.Description,
         Amount      = productStockData.Amount
     };
     return(productStock);
 }
コード例 #3
0
        private ProductStockData ParseProductStockToProductStockData(StockEntityModel.ProductStock productStock)
        {
            ProductStockData productStockData = new ProductStockData()
            {
                Number      = productStock.Number,
                Name        = productStock.Name,
                Description = productStock.Description,
                Amount      = productStock.Amount
            };

            return(productStockData);
        }
コード例 #4
0
 public bool CreateProductStock(StockEntityModel.ProductStock productStock)
 {
     try
     {
         using (StockProvider database = new StockProvider())
         {
             database.ProductsStock.Add(productStock);
             database.SaveChanges();
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
        public ProductStockData RetrieveProductStock(string productNumber)
        {
            ProductStockData productStockData = null;

            try
            {
                using (StockProvider database = new StockProvider())
                {
                    StockEntityModel.ProductStock productStock = database.ProductsStock.First(
                        p => String.Compare(p.Number, productNumber) == 0);
                    productStockData = ParseProductStockToProductStockData(productStock);
                }
            }
            catch
            {
                //TODO: Should be implemented in future
            }
            return(productStockData);
        }