コード例 #1
0
        public bool Add(ProductVM model)
        {
            try
            {
                DateTime dateTime = DateTime.Now;
                model.Buys.DateBuy = DateTime.Parse(dateTime.ToShortDateString());
                _dbContext.Add(model);
                _dbContext.SaveChanges();
                var        max = _dbContext.Buys.Max(e => e.Id);
                BuyProduct buyProduct;
                foreach (var item in model.Products)
                {
                    buyProduct         = new BuyProduct();
                    buyProduct.Id      = item.Id;
                    buyProduct.IdBuy   = max;
                    buyProduct.Quatity = item.Quatity;
                    _dbContext.BuyProducts.Add(buyProduct);
                    _dbContext.SaveChanges();

                    var NQuantity = _dbContext.Products.Find(buyProduct.IdProduct);
                    NQuantity.Quatity = NQuantity.Quatity - item.Quatity;
                    _dbContext.Products.Update(NQuantity);
                    _dbContext.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
コード例 #2
0
 public bool Add(Product model)
 {
     try
     {
         _dbContext.Add(model);
         _dbContext.SaveChanges();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
コード例 #3
0
 public bool Add(User model)
 {
     try
     {
         _businessLogicDbContext.Add(model);
         _businessLogicDbContext.SaveChanges();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }