public bool UpdateRawUnit(RawUnit rw)
 {
     if (rw == null)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.RawUnit.SingleOrDefault(bt => bt.UnitId == rw.UnitId);
             if (type != null)
             {
                 type.Deleted        = rw.Deleted;
                 type.Name           = rw.Name;
                 type.Status         = rw.Status;
                 type.UpdateBy       = rw.UpdateBy;
                 type.UpdateDatetime = rw.UpdateDatetime;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
         return(false);
     }
 }
 public bool DeleteRawUnit(int id)
 {
     if (id < 0)
     {
         return(false);
     }
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             RawUnit booktype = new RawUnit()
             {
                 UnitId = id,
             };
             DbEntityEntry <RawUnit> entry = entities.Entry <RawUnit>(booktype);
             entry.State = EntityState.Deleted;
             entities.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
     }
 }
 /**根据传入的原料单位对象获取BaseMaterialBean对象*/
 public BaseMaterialBean CreateBaseMaterialBean(RawUnit bean)
 {
     this.Id             = bean.UnitId;
     this.Name           = bean.Name;
     this.CreateDatetime = bean.CreateDatetime;
     this.CreateBy       = bean.CreateBy;
     this.Deleted        = bean.Deleted;
     this.Status         = bean.Status;
     this.UpdateDatetime = bean.UpdateDatetime;
     this.UpdateBy       = bean.UpdateBy;
     return(this);
 }
        /**根据传入的原料单位对象获取原料单位对象*/
        public RawUnit CreateRawUnitBean(BaseMaterialBean bean)
        {
            RawUnit beanBack = new RawUnit();

            beanBack.UnitId         = bean.Id;
            beanBack.Name           = bean.Name;
            beanBack.CreateDatetime = bean.CreateDatetime;
            beanBack.CreateBy       = bean.CreateBy;
            beanBack.Deleted        = bean.Deleted;
            beanBack.Status         = bean.Status;
            beanBack.UpdateDatetime = bean.UpdateDatetime;
            beanBack.UpdateBy       = bean.UpdateBy;
            return(beanBack);
        }
 public RawUnit AddRawUnit(RawUnit rw)
 {
     if (rw == null)
     {
         return(null);
     }
     //添加
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             RawUnit ru = entities.RawUnit.Add(rw);
             entities.SaveChanges();
             return(ru);
         }
         catch (Exception e)
         {
             e.ToString();
             return(null);
         }
     }
 }