示例#1
0
 public IList <Goods> ViewGoods(bool?isSpecial)
 {
     using (ShopPingEntities en = new ShopPingEntities())
     {
         IList <NewShop> lst;
         if (isSpecial == null)
         {
             lst = en.NewShops.ToList();
         }
         else
         {
             lst = en.NewShops.Where(x => x.IsSpecial != isSpecial).ToList();
         }
         return(lst.Select(x => this.ConvertEntityToGoods(x)).ToList());
     }
 }
示例#2
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);
     }
 }
示例#3
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);
     }
 }
示例#4
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);
            }
        }