Пример #1
0
 public bool DeleteGoods(int id)
 {
     try
     {
         using (ShopPingEntities en = new ShopPingEntities())
         {
             NewShop newShop = en.NewShops.First(x => x.ShopID == id);
             en.NewShops.Remove(newShop);
             en.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Пример #2
0
 public bool EditGoods(int id, Goods newGoods)
 {
     try
     {
         using (ShopPingEntities en = new ShopPingEntities())
         {
             NewShop newShop = en.NewShops.First(x => x.ShopID == id);
             newShop.ShopName     = newGoods.Name;
             newShop.ShopLei      = newGoods.Category;
             newShop.ShopMoney    = newGoods.Price;
             newShop.ShopPreMoney = newGoods.PrePrice;
             newShop.IsSpecial    = newGoods.isSpecial;
             en.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Пример #3
0
        public bool AddGoods(Goods goods)
        {
            NewShop newShop = this.ConvertGoodsToEntity(goods);

            try
            {
                using (ShopPingEntities en = new ShopPingEntities())
                {
                    en.NewShops.Add(newShop);
                    en.SaveChanges();
                }
                return(true);
            }
            //数据库操作如果失败,
            //可以想办法获取ex.Message并传到外部,
            //这里简单屏蔽掉了
            //下同
            catch (Exception ex)
            {
                return(false);
            }
        }