Beispiel #1
0
        //0修改失败,-1修改重复
        public int EditByCompany(Company company)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //查询公司是否存在
                var type = entities.Company.SingleOrDefault(bt => bt.CompanyId == company.CompanyId && bt.Deleted == 0);
                if (type != null)
                {
                    //设置属性是否参与修改 ,设置为false则无法更新数据
                    type.CompanyName = company.CompanyName;
                    type.Contacts    = company.Contacts;
                    type.Phone       = company.Phone;
                    type.Mobile      = company.Mobile;
                    type.Email       = company.Email;
                    type.Addr        = company.Addr;
                    type.Logo1       = company.Logo1;
                    type.Logo2       = company.Logo2;
                    type.DPName      = company.DPName;
                    type.DPAddr      = company.DPAddr;
                    type.DPParam     = company.DPParam;
                    type.EditPerson  = company.EditPerson;
                    type.EditTime    = company.EditTime;
                    try
                    {
                        //关闭实体验证,不关闭验证需要整个对象全部传值
                        entities.Configuration.ValidateOnSaveEnabled = false;
                        //操作数据库
                        flag = entities.SaveChanges();
                        entities.Configuration.ValidateOnSaveEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                    //实体绑定MODEL
                    entities.Company.Add(company);
                    try
                    {
                        //操作数据库
                        entities.Configuration.ValidateOnSaveEnabled = false;

                        flag = entities.SaveChanges();
                        entities.Configuration.ValidateOnSaveEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
            }
            return(flag);
        }
        public int addBearing(string name, string no)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                Bearing bear = new Bearing()
                {
                    Code           = int.Parse(no),
                    Name           = name,
                    CreateDatetime = DateTime.Now,
                    CreateBy       = 1,
                    Deleted        = 1,
                    Status         = 1
                };
                entities.Bearing.Add(bear);
                try
                {
                    flag = entities.SaveChanges();
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return(flag);
        }
        //根据做法类型编码删除菜品做法类型,如果删除失败返回false,如果删除成功,则返回true
        public bool DeleteDischesWayName(int id)
        {
            //先判断是否存在有做法,如果有做法,则不能返回false
            DischesWayDataService odws          = new DischesWayDataService();
            List <DischesWay>     orgDischesWay = odws.FindAllDischesWay(id);

            if (orgDischesWay != null)
            {
                return(false);
            }
            //删除
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                DischesWayName booktype = new DischesWayName()
                {
                    DischesWayNameId = id,
                };
                DbEntityEntry <DischesWayName> entry = entities.Entry <DischesWayName>(booktype);
                entry.State = System.Data.EntityState.Deleted;

                entities.SaveChanges();

                var newtype = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == id);
                if (newtype != null)
                {
                    //Console.WriteLine(newtype.name);
                    return(false);
                }
                else
                {
                    //Console.WriteLine("No Found");
                    return(true);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 为制定的用户设置角色
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="roles"></param>
        public void Grant(int userId, int[] roles)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                UserInfo userInfo = entities.UserInfo.Find(userId);
                if (null == userInfo)
                {
                    throw new ServiceException("未找到对应的用户【" + userId + "】");
                }

                List <UserRoleRef> _RefList = new List <UserRoleRef>();
                int      authId             = SubjectUtils.GetAuthenticationId();
                DateTime now = DateTime.Now;
                foreach (var r in roles)
                {
                    UserRoleRef _ref = new UserRoleRef();
                    _ref.RoleId         = r;
                    _ref.UserId         = userId;
                    _ref.CreateBy       = authId;
                    _ref.CreateDateTime = now;
                    _RefList.Add(_ref);
                }
                entities.UserRoleRef.AddRange(_RefList);
                entities.SaveChanges();

                Log.M(Loggers.USER_GRANT_ROLE, authId, userId, new object[] { roles });
            }
        }
 public bool DeleteMarketTypeById(int id)
 {
     if (id < 0)
     {
         return(false);
     }
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             MarketType booktype = new MarketType()
             {
                 Id = id,
             };
             DbEntityEntry <MarketType> entry = entities.Entry <MarketType>(booktype);
             entry.State = EntityState.Deleted;
             entities.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
     }
 }
 public bool DeleteRaw(int id)
 {
     if (id < 0)
     {
         return(false);
     }
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             Raw booktype = new Raw()
             {
                 RawId = id,
             };
             DbEntityEntry <Raw> entry = entities.Entry <Raw>(booktype);
             entry.State = EntityState.Deleted;
             entities.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
     }
 }
Beispiel #7
0
 /**根据做法对象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 Modify(DischesWay odw)
 {
     if (odw == null)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             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.AddPrice       = odw.AddPrice;
                 type.AddPriceByNum  = odw.AddPriceByNum;
                 type.Deleted        = odw.Deleted;
                 type.PingYing       = odw.PingYing;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
         return(false);
     }
 }
Beispiel #8
0
 //修改菜品做法类型,传入的参数需要包含:DischesWayNameId/Code,Name,Status,Deleted,UpdateBy,UpdateDatetime字段
 public bool UpdateDishesWayName(DischesWayName dwn)
 {
     if (dwn == null)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == dwn.DischesWayNameId);
             if (type != null)
             {
                 type.Name           = dwn.Name;
                 type.Status         = dwn.Status;
                 type.UpdateBy       = dwn.UpdateBy;
                 type.UpdateDatetime = dwn.UpdateDatetime;
                 type.Deleted        = dwn.Deleted;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
     }
     return(false);
 }
Beispiel #9
0
        public int DelByDepartment(DepartmentInfo departmentInfo)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //直接修改的方式
                DbEntityEntry <DepartmentInfo> entry = entities.Entry <DepartmentInfo>(departmentInfo);
                entry.State = System.Data.Entity.EntityState.Unchanged;
                //设置修改状态为ture 否则数据库不会更新
                entry.Property("UpdateBy").IsModified       = true;
                entry.Property("Deleted").IsModified        = true;
                entry.Property("UpdateDatetime").IsModified = true;
                try
                {
                    //关闭实体验证,不关闭验证需要整个对象全部传值
                    entities.Configuration.ValidateOnSaveEnabled = false;
                    flag = entities.SaveChanges();
                    entities.Configuration.ValidateOnSaveEnabled = true;
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return(flag);
        }
Beispiel #10
0
        //0 添加失败,-1添加重复
        public int AddDepartment(DepartmentInfo departmentInfo)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //查询编码是否存在
                var type = entities.DepartmentInfo.SingleOrDefault(bt => bt.DepartmentName == departmentInfo.DepartmentName && bt.Deleted == 0);
                if (type == null)
                {
                    //实体绑定MODEL
                    entities.DepartmentInfo.Add(departmentInfo);
                    try
                    {
                        //操作数据库
                        entities.Configuration.ValidateOnSaveEnabled = false;

                        flag = entities.SaveChanges();
                        entities.Configuration.ValidateOnSaveEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                    flag = -1;
                }
            }
            return(flag);
        }
        public int delByLocation(string id)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                Location local = new Location()
                {
                    LocationId     = int.Parse(id),
                    Deleted        = 1,
                    UpdateBy       = 1,
                    UpdateDatetime = DateTime.Now
                };
                DbEntityEntry <Location> entry = entities.Entry <Location>(local);
                entry.State = System.Data.EntityState.Unchanged;
                entry.Property("Deleted").IsModified        = true;
                entry.Property("UpdateBy").IsModified       = true;
                entry.Property("UpdateDatetime").IsModified = true;
                try
                {
                    entities.Configuration.ValidateOnSaveEnabled = false;
                    flag = entities.SaveChanges();
                    entities.Configuration.ValidateOnSaveEnabled = true;
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return(flag);
        }
        public int editByLocation(string id, string name, string no)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                Location local = new Location()
                {
                    LocationId     = int.Parse(id),
                    Code           = no,
                    Name           = name,
                    UpdateBy       = 1,
                    UpdateDatetime = DateTime.Now
                };
                DbEntityEntry <Location> entry = entities.Entry <Location>(local);
                entry.State = System.Data.EntityState.Unchanged;
                entry.Property("Code").IsModified           = true;
                entry.Property("Name").IsModified           = true;
                entry.Property("UpdateBy").IsModified       = true;
                entry.Property("UpdateDatetime").IsModified = true;
                try
                {
                    flag = entities.SaveChanges();
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return(flag);
        }
        public int addLocation(string name, string no)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                Location local = new Location()
                {
                    Code           = no,
                    Name           = name,
                    CreateDatetime = DateTime.Now,
                    CreateBy       = 1,
                    Deleted        = 0,
                    Status         = 0
                };
                entities.Location.Add(local);
                try
                {
                    flag = entities.SaveChanges();
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return(flag);
        }
 //删除收银方式 返回true 为修改成功
 public bool deleteCashType(int Id)
 {
     try
     {
         using (ChooseDishesEntities entities = new ChooseDishesEntities())
         {
             var type = entities.CashType.SingleOrDefault(bt => bt.Id == Id);
             if (type != null)
             {
                 type.Deleted = 1;
                 entities.SaveChanges();
             }
             else
             {
                 return(false);
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         e.ToString();
         return(false);
     }
 }
 //添加收银方式 返回添加成功后的收银方式
 public CashType addCashType(CashType cashType)
 {
     try
     {
         if (cashType == null)
         {
             return(null);
         }
         CashType newCashType = null;
         using (ChooseDishesEntities entities = new ChooseDishesEntities())
         {
             var type = entities.CashType.SingleOrDefault(bt => bt.Code == cashType.Code);
             if (type != null)
             {
                 return(null);
             }
             entities.CashType.Add(cashType);
             entities.SaveChanges();
             var typenew = entities.CashType.SingleOrDefault(bt => bt.Code == cashType.Code);
             if (typenew != null)
             {
                 newCashType = type;
             }
         }
         return(newCashType);
     }
     catch (Exception e)
     {
         e.ToString();
         return(null);
     }
 }
Beispiel #16
0
 //根据外卖客户id修改外卖客户信息
 public bool UpdateTakeoutClientInfo(TakeoutClientInfo info)
 {
     if (info == null)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.TakeoutClientInfo.SingleOrDefault(bt => bt.OrderPeopleId == info.OrderPeopleId);
             if (type != null)
             {
                 type.Order_people    = info.Order_people;
                 type.Mobile          = info.Mobile;
                 type.Status          = info.Status;
                 type.Telephone       = info.Telephone;
                 type.Update_by       = info.Update_by;
                 type.Update_datetime = info.Update_datetime;
                 type.Address         = info.Address;
                 type.Deleted         = info.Deleted;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
         return(false);
     }
 }
Beispiel #17
0
 //根据外卖客户id修改外卖客户Deleted状态
 public bool UpdateTakeoutClientDeletedById(int id, int DeletedStatas)
 {
     if (id < 0)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.TakeoutClientInfo.SingleOrDefault(bt => bt.OrderPeopleId == id);
             if (type != null)
             {
                 type.Deleted = DeletedStatas;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
         return(false);
     }
 }
Beispiel #18
0
        //0 添加失败,-1添加重复
        public int AddEmployee(Employee employee)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //查询员工工号是否存在
                var type = entities.Employee.SingleOrDefault(bt => bt.JobNo == employee.JobNo && bt.Deleted == 0);
                if (type == null)
                {
                    //实体绑定MODEL
                    entities.Employee.Add(employee);
                    try
                    {
                        //操作数据库
                        entities.Configuration.ValidateOnSaveEnabled = false;

                        flag = entities.SaveChanges();
                        entities.Configuration.ValidateOnSaveEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                    flag = -1;
                }
            }
            return(flag);
        }
Beispiel #19
0
 //根据做法类型id修改删除状态
 public bool UpdateDishesWayNameDeletedTypeById(int Id)
 {
     if (Id == null)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == Id);
             if (type != null)
             {
                 type.UpdateBy       = SubjectUtils.GetAuthenticationId(); //操作人员id
                 type.UpdateDatetime = DateTime.Now;
                 type.Deleted        = 1;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
     }
     return(false);
 }
Beispiel #20
0
        //0 添加失败,-1添加重复
        public int AddCompany(Company company)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //查询编码是否存在
                var type = entities.Company.SingleOrDefault(bt => bt.CompanyId == company.CompanyId && bt.Deleted == 0);
                if (type == null)
                {
                    //实体绑定MODEL
                    entities.Company.Add(company);
                    try
                    {
                        //操作数据库
                        entities.Configuration.ValidateOnSaveEnabled = false;

                        flag = entities.SaveChanges();
                        entities.Configuration.ValidateOnSaveEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                    flag = -1;
                }
            }
            return(flag);
        }
 public bool UpdateRaw(Raw rw)
 {
     if (rw == null)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.Raw.SingleOrDefault(bt => bt.RawId == rw.RawId);
             if (type != null)
             {
                 type.ParentRawId    = rw.ParentRawId;
                 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);
     }
 }
Beispiel #22
0
        //员工状态修改
        public int EditEmployeeFlag(Employee employee)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //直接修改的方式
                DbEntityEntry <Employee> entry = entities.Entry <Employee>(employee);
                entry.State = System.Data.Entity.EntityState.Unchanged;
                //设置修改状态为ture 否则数据库不会更新
                entry.Property("UpdateDatetime").IsModified = true;
                entry.Property("Flag").IsModified           = true;
                entry.Property("UpdateBy").IsModified       = true;
                try
                {
                    //关闭实体验证,不关闭验证需要整个对象全部传值
                    entities.Configuration.ValidateOnSaveEnabled = false;
                    flag = entities.SaveChanges();
                    entities.Configuration.ValidateOnSaveEnabled = true;
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            return(flag);
        }
 /**根据原料id和指定的删除状态修改原料的删除状态*/
 public bool UpdateRawMaterialDeletedStatusById(int Id, int DeletedStatus)
 {
     if (Id < 0)
     {
         return(false);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.RawMaterial.SingleOrDefault(bt => bt.Id == Id);
             if (type != null)
             {
                 type.Deleted = DeletedStatus;
                 entities.SaveChanges();
                 return(true);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
         return(false);
     }
 }
        //根据做法类型编码删除菜品做法类型,如果删除失败返回false,如果删除成功,则返回true
        public bool DeleteDishesWayNameByCode(int id)
        {
            //先判断是否存在有做法,如果有做法,则不能返回false
            List <DischesWay> orgDischesWay = FindAllDishesWayByTypeId(id);

            if (orgDischesWay != null && orgDischesWay.Count > 0)
            {
                return(false);
            }
            //删除
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    DischesWayName booktype = new DischesWayName()
                    {
                        DischesWayNameId = id,
                    };
                    DbEntityEntry <DischesWayName> entry = entities.Entry <DischesWayName>(booktype);
                    entry.State = System.Data.Entity.EntityState.Deleted;

                    entities.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    e.ToString();
                    return(false);
                }
            }
        }
 public MarketType UpdateMarketType(MarketType mt)
 {
     if (mt == null)
     {
         return(null);
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.MarketType.SingleOrDefault(bt => bt.Id == mt.Id);
             if (type != null)
             {
                 type.Deleted        = mt.Deleted;
                 type.Name           = mt.Name;
                 type.StartTime      = mt.StartTime;
                 type.Status         = mt.Status;
                 type.UpdateBy       = mt.UpdateBy;
                 type.UpdateDatetime = mt.UpdateDatetime;
                 entities.SaveChanges();
                 return(type);
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return(null);
         }
         return(null);
     }
 }
 public bool Add(string _Code, int _DishesWayNameId, string _Name, string _PingYing, double _AddPrice, int _AddPriceByNum)
 {
     //添加
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             DischesWay odw = new DischesWay();
             odw.Code             = _Code;
             odw.DischesWayNameId = _DishesWayNameId;
             odw.Name             = _Name;
             odw.PingYing         = _PingYing;
             odw.AddPrice         = _AddPrice;
             odw.AddPriceByNum    = _AddPriceByNum;
             odw.CreateBy         = SubjectUtils.GetAuthenticationId();
             odw.CreateDatetime   = DateTime.Now;
             entities.DischesWay.Add(odw);
             entities.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             e.ToString();
             return(false);
         }
     }
 }
Beispiel #27
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="employeeId"></param>
        public int Add(int employeeId, string username, string passwd)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities()) {
                Employee employee = entities.Employee.Find(employeeId);
                if (null == employee)
                {
                    throw new ServiceException("无法找到对应的员工,编号为:【" + employeeId + "】");
                }
                int      authorId  = SubjectUtils.GetAuthenticationId();
                UserInfo _UserInfo = new UserInfo();

                _UserInfo.EmployeeId = employeeId;
                if (null != username || null != passwd)
                {
                    _UserInfo.Username = username;
                    _UserInfo.Salt     = CryptoUtils.GetSalt();
                    _UserInfo.Password = CryptoUtils.MD5Encrypt(passwd);
                    _UserInfo.CreateBy = SubjectUtils.GetAuthenticationId();
                }
                _UserInfo.CreateDatetime = DateTime.Now;
                entities.UserInfo.Add(_UserInfo);
                try
                {
                    entities.SaveChanges();
                    Log.A(Loggers.USER_NEW, authorId, _UserInfo.UserId);
                }catch (DbEntityValidationException e) {
                    throw new ServiceException(e.Message);
                }
                return(_UserInfo.UserId);
            }
        }
Beispiel #28
0
        //删除外卖单

        public bool DeletedTakeoutOrder(int id)
        {
            if (id < 0)
            {
                return(false);
            }
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    TakeoutOrder booktype = new TakeoutOrder()
                    {
                        TakeoutId = id,
                    };
                    DbEntityEntry <TakeoutOrder> entry = entities.Entry <TakeoutOrder>(booktype);
                    entry.State = EntityState.Deleted;
                    entities.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    e.ToString();
                    return(false);
                }
            }
        }
        //0修改失败,-1修改重复
        public int UpdateDetail(DiscountDetail Detail)
        {
            int flag = 0;

            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                //查询折扣方案是否存在
                var type = entities.DiscountDetail.SingleOrDefault(bt => bt.Id == Detail.Id && bt.Deleted == 0);
                if (type != null)
                {
                    //设置属性是否参与修改 ,设置为false则无法更新数据
                    type.DiscountValue  = Detail.DiscountValue;
                    type.UpdateDatetime = Detail.UpdateDatetime;
                    type.UpdateBy       = Detail.UpdateBy;
                    try
                    {
                        //关闭实体验证,不关闭验证需要整个对象全部传值
                        entities.Configuration.ValidateOnSaveEnabled = false;
                        //操作数据库
                        flag = entities.SaveChanges();
                        entities.Configuration.ValidateOnSaveEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
            }
            return(flag);
        }
Beispiel #30
0
        //新增桌类
        public int SaveTableType(TableType type)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    Hashtable hash = new Hashtable();//返回结果

                    List <TableType> types;
                    //检查类型编号或者类型名称是否重复
                    types = entities.TableType.Where(info => info.Name == type.Name || info.Code == type.Code).ToList();
                    if (types != null && types.Count > 0)
                    {
                        hash.Add("code", 1);
                        if (types[0].Name == type.Name)
                        {
                            throw new ServiceException("类型名称已经存在,请重新命名!");
                        }
                        else if (types[0].Code == type.Code)
                        {
                            throw new ServiceException("类型编号已经存在!");
                        }
                    }
                    entities.TableType.Add(type);
                    entities.SaveChanges();
                    return(type.TableTypeId);
                }
                catch (Exception e)
                {
                    throw new ServiceException(e.Message);
                }
            };
        }