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());
     }
 }
 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);
     }
 }
 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);
     }
 }
        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);
            }
        }