/// <summary>
        /// 把Goods转换为数据库对象
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        private NewShop ConvertGoodsToEntity(Goods goods)
        {
            NewShop newShop = new NewShop();

            newShop.ShopName     = goods.Name;
            newShop.ShopLei      = goods.Category;
            newShop.ShopMoney    = goods.Price;
            newShop.ShopPreMoney = goods.PrePrice;
            newShop.IsSpecial    = goods.isSpecial;
            return(newShop);
        }
        /// <summary>
        /// 把数据库对象转换为Goods
        /// </summary>
        /// <param name="newShop"></param>
        /// <returns></returns>
        private Goods ConvertEntityToGoods(NewShop newShop)
        {
            Goods goods = new Goods();

            goods.Id        = newShop.ShopID;
            goods.Name      = newShop.ShopName;
            goods.Category  = newShop.ShopLei;
            goods.Price     = newShop.ShopMoney;
            goods.PrePrice  = newShop.ShopPreMoney;
            goods.isSpecial = newShop.IsSpecial;
            return(goods);
        }
 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);
            }
        }