/**根据做法对象id作为参数修改做法
                     type.Name = odw.Name;   
                    type.Status = odw.Status;
                    type.UpdateBy = odw.UpdateBy;    //修改人编号
                    type.UpdateDatetime = odw.UpdateDatetime;   //修改时间
                    type.WayDetail = odw.WayDetail;
                    type.DischesWayId = odw.DischesWayId;
                    type.AddPrice = odw.AddPrice;
                    type.AddPriceByNum = odw.AddPriceByNum;
                    type.Deleted = odw.Deleted;
                    type.PingYing = odw.PingYing;
         */
        public bool UpdateDischesWay(DischesWay odw)
        {
            if (odw == null)
            {
                return false;
            }
            //修改  直接修改
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {

                var type = entities.DischesWay.SingleOrDefault(bt => bt.DischesWayId == odw.DischesWayId);
                if (type != null)
                {
                    type.Name = odw.Name;
                    type.Status = odw.Status;
                    type.UpdateBy = odw.UpdateBy;
                    type.UpdateDatetime = odw.UpdateDatetime;
                    type.WayDetail = odw.WayDetail;
                    type.DischesWayId = odw.DischesWayId;
                    type.AddPrice = odw.AddPrice;
                    type.AddPriceByNum = odw.AddPriceByNum;
                    type.Deleted = odw.Deleted;
                    type.PingYing = odw.PingYing;
                }
                entities.SaveChanges();

                var newtype = entities.DischesWay.SingleOrDefault(bt => bt.DischesWayId == odw.DischesWayId);
                if (newtype != null)
                {
                    return true;
                }  
            }
            return false;
        }
 /**添加做法,传入的对象需要封装如下信息
         DischesWayId=1,    
        DischesWayNameId=2,    //做法类型id
        CreateDatetime=DateTime.Now,    //创建时间
        CreateBy=1,      //创建人编号
        Code=1,         //做法编码
        AddPrice=2,     //是否加价,默认为0
        Deleted=0,      //是否删除
        Name="三分熟加辣",    //做法名称
        Status=0,    //状态
        AddPriceByNum=0,     //是否按照分数加价
        PingYing="sfsjl",     //做法拼音
        WayDetail="要三分熟就可以了"    //做法说明(非必填)
  */
 public bool AddDischesWay(DischesWay odw)
 {
     //添加
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         entities.DischesWay.Add(odw);
         entities.SaveChanges();
         var type = entities.DischesWay.SingleOrDefault(bt => bt.DischesWayId == odw.DischesWayId);
         if (type != null)
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
        public void TestMethodAddDischesWay()
        {
            DischesWayDataService dd = new DischesWayDataService();
            DischesWay dw = new DischesWay()
            {
               DischesWayId=1,
               DischesWayNameId=2,
               CreateDatetime=DateTime.Now,
               CreateBy=1,
               Code=1,
               AddPrice=2,
               Deleted=0,
               Name="三分熟加辣",
               Status=0,
               AddPriceByNum=0,
               PingYing="sfsjl",
               WayDetail="要三分熟就可以了"
            };
            var f = dd.AddDischesWay(dw);

        }
        /**根据指定编码删除对应做法*/
        public bool DeleteDischesWay(int id)
        {

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                var type = entities.DischesWay.SingleOrDefault(bt => bt.DischesWayId == id);
                if (type == null)
                {
                    return false;
                }
                DischesWay booktype = new DischesWay()
                {
                    DischesWayId = id,
                };
                DbEntityEntry<DischesWay> entry = entities.Entry<DischesWay>(booktype);
                entry.State = System.Data.EntityState.Deleted;

                entities.SaveChanges();
                return true;
            }
        }