//根据做法类型编码删除菜品做法类型,如果删除失败返回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); } } }
/// <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); } }
//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); }
/// <summary> /// 查询角色权限 /// </summary> /// <param name="roleId">角色编号</param> public List <RoleRefFunction> QueryFunctionForRole(int roleId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.RoleRefFunction.Where(t => t.Deleted == 0 && t.RoleId == roleId).ToList()); } }
/// <summary> /// 获取所有父模块 /// <para>get all of root Module from table Module where ParentId=null</para> /// </summary> /// <returns>return the list of root Module object which is not null ,else if return null</returns> public List <Module> QueryModulesParent() { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.Module.Where(t => t.Deleted == 0 && (t.ParentId == null)).ToList()); } }
/// <summary> /// 查询用户并返回关联的用户角色 /// </summary> /// <param name="userId"></param> /// <returns></returns> public UserInfo FindWithRelation(int userId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.UserInfo.Include(typeof(Employee).Name).Include(typeof(UserSaleRule).Name).Include(typeof(UserRoleRef).Name).Where(t => t.UserId == userId && t.Deleted == 0).SingleOrDefault()); } }
/// <summary> /// 查询所有可用的权限 /// </summary> /// <returns></returns> public List <Function> QueryFunction() { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.Function.Where(t => t.Deleted == 0).ToList()); } }
//根据做法类型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); }
/**根据做法对象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); } }
//根据外卖客户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); } }
//修改菜品做法类型,传入的参数需要包含: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); }
//根据外卖客户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); } }
//删除外卖单 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); } } }
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); } } }
/// <summary> /// 查询用户角色 /// </summary> /// <returns></returns> public List <UserRoleRef> QueryRolesByUserId(int id) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.UserRoleRef.Where(t => t.Deleted == 0 && t.UserId == id).ToList()); } }
public bool FindRawUnitByName(List <string> names) { if (names == null) { return(false); } using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { foreach (var name in names) { //遍历所有的名称,如果在数据表中找到记录,则type不为空,返回true,如果为空,则表示没有 var type = entities.RawUnit.SingleOrDefault(bt => bt.Name.Equals(name)); if (type != null) { return(true); } } return(false); } catch (Exception e) { e.ToString(); return(false); } } }
/// <summary> /// 通过用户ID 查询用户 /// /// </summary> /// <param name="userId"></param> /// <returns></returns> public UserInfo Find(int userId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.UserInfo.Where(t => t.UserId == userId && t.Deleted == 0).SingleOrDefault()); } }
public List <DischesWayRef> QueryAllByDishesId(int dishesId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.DischesWayRef.Include(typeof(DischesWay).Name).Where(d => d.Deleted == 0 && d.DishId == dishesId).ToList()); } }
/// <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 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); } }
/// <summary> /// 查询指定模块的功能权限 /// </summary> /// <param name="module">模块名称</param> /// <returns></returns> public List <Function> QueryFunction(string module) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.Function.Where(t => t.Deleted == 0 && t.ModuleId == module).ToList()); } }
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); } } }
/// <summary> /// 获取模块并查询模块对应的功能 /// </summary> /// <returns></returns> public List <Module> QueryModuleWithFunctions() { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.Module.Include(typeof(Function).Name).Where(t => t.Deleted == 0).ToList()); } }
/**根据原料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); } }
/// <summary> /// 根据模块父模块获取所有子模块 /// <para>get all of sub Module from table Module where ParentId=parentId</para> /// </summary> /// <returns>return the list of sub Module object which is not null ,else if return null</returns> public List <Module> QueryModulesByParentId(string parentId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.Module.Where(t => t.Deleted == 0 && (t.ParentId.Equals(parentId))).ToList()); } }
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); } } }
//根据做法类型编码删除菜品做法类型,如果删除失败返回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); } } }
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 List <TableItem> GetAll() { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { return(entities.TableItem.Include(typeof(Table).Name).Where(t => t.Deleted == 0).ToList()); } }
public DishType LoadFatherTypeById(int Id) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DishType fatherType; DishType type; type = (DishType)entities.DishType.Include("Dish").Where(info => info.DishTypeId == Id); if (type == null) { fatherType = new DishType(); return(fatherType); } fatherType = (DishType)entities.DishType.Include("Dish").Where(info => info.DishTypeId == type.ParentId); if (fatherType == null) { fatherType = new DishType(); } return(fatherType); }; } catch (Exception e) { throw e; } }