//0修改失败,-1修改重复 public int editByLocation(Location local) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //查询编码是否存在 var type = entities.Location.SingleOrDefault(bt => bt.Code == local.Code && bt.Deleted == 0 && bt.LocationId != local.LocationId); if (type == null) { DbEntityEntry<Location> entry = entities.Entry<Location>(local); //设置操作类型 entry.State = System.Data.Entity.EntityState.Unchanged; //设置属性是否参与修改 ,设置为false则无法更新数据 entry.Property("Code").IsModified = true; entry.Property("Name").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(); } } else { flag = -1; } } return flag; }
//删除道菜 public int delDishDao(DishDao dishDao) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //直接修改的方式 DbEntityEntry<DishDao> entry = entities.Entry<DishDao>(dishDao); 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; }
//0修改失败,-1修改重复 public int editByBearing(Bearing bearing) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { var type = entities.Bearing.SingleOrDefault(bt => bt.Code == bearing.Code && bt.Deleted == 0 && bt.BearingId != bearing.BearingId); if (type == null) { //实体绑定model DbEntityEntry<Bearing> entry = entities.Entry<Bearing>(bearing); //设置操作类型 entry.State = System.Data.Entity.EntityState.Unchanged; //设置修改状态为ture 否则数据库不会更新 entry.Property("Code").IsModified = true; entry.Property("Name").IsModified = true; entry.Property("Status").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(); } } else { flag = -1; } } return flag; }
public int delByLocation(Location location) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DbEntityEntry<Location> entry = entities.Entry<Location>(location); //设置操作类型 entry.State = System.Data.Entity.EntityState.Unchanged; //设置属性是否参与修改 ,设置为false则无法更新数据 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 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 DeleteProgram(int typeId) { bool flag = true; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Expression<Func<DiscountProgram, bool>> checkCourse = Program => Program.DiscountId == typeId && Program.Deleted == 0; //先查询 后修改 List<DiscountProgram> type = entities.DiscountProgram.Where(checkCourse).ToList(); if (type != null && type.Count > 0) { foreach (var t in type) { t.UpdateBy = SubjectUtils.GetAuthenticationId(); t.UpdateDatetime = DateTime.Now; t.Deleted = 1; //直接修改的方式 DbEntityEntry<DiscountProgram> entry = entities.Entry<DiscountProgram>(t); entry.State = System.Data.Entity.EntityState.Modified; //设置修改状态为ture 否则数据库不会更新 entry.Property("UpdateBy").IsModified = true; entry.Property("Deleted").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; try { //关闭实体验证,不关闭验证需要整个对象全部传值 entities.Configuration.ValidateOnSaveEnabled = false; var result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result <= 0) { return false; } } catch (Exception ex) { ex.ToString(); } } } return flag; } }
public bool DeleteType(int typeId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DishType type = new DishType(); type.DishTypeId = typeId; type.Deleted = 1; DbEntityEntry<DishType> entry = entities.Entry<DishType>(type); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Deleted").IsModified = true; entry.Property("DishTypeId").IsModified = false; entities.Configuration.ValidateOnSaveEnabled = false; var result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return true; } else { return false; } } }
/**根据指定编码删除对应做法*/ public bool Deleted(int id) { if (id < 0) { return false; } using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { DischesWay booktype = new DischesWay() { DischesWayId = id, }; DbEntityEntry<DischesWay> entry = entities.Entry<DischesWay>(booktype); entry.State = EntityState.Deleted; entities.SaveChanges(); return true; } catch (Exception e) { e.ToString(); 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 DeleteTable(int tableId) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { IShow.ChooseDishes.Data.Table table = new IShow.ChooseDishes.Data.Table(); table.TableId = tableId; DbEntityEntry<IShow.ChooseDishes.Data.Table> entry = entities.Entry<IShow.ChooseDishes.Data.Table>(table); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Deleted").IsModified = true; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return true; } else { return false; } } } catch (Exception e) { throw e; } }
public bool UpdateTable(IShow.ChooseDishes.Data.Table table) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DbEntityEntry<IShow.ChooseDishes.Data.Table> entry = entities.Entry<IShow.ChooseDishes.Data.Table>(table); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Name").IsModified = true; entry.Property("Seat").IsModified = true; entry.Property("TableTypeId").IsModified = true; entry.Property("LocationId").IsModified = true; entry.Property("Status").IsModified = true; //TODO 是否已经启用,已启用则不能删除 entry.Property("TableId").IsModified = false; try { entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return true; } else { return false; } } catch (Exception e) { Console.WriteLine(e.ToString()); return false; } } }
/// <summary> /// 删除 /// </summary> /// <param name="detailId"></param> /// <returns></returns> public bool DeleteTableTypeDetail(int detailId) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { TableTypeDetail detail = new TableTypeDetail(); detail.TableTypeDetailId = detailId; detail.Deleted = 1; DbEntityEntry<IShow.ChooseDishes.Data.TableTypeDetail> entry = entities.Entry<IShow.ChooseDishes.Data.TableTypeDetail>(detail); entry.State = System.Data.Entity.EntityState.Unchanged; entry.Property("Deleted").IsModified = true; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = false; if (result == 1) { return true; } else { return false; } } } catch (Exception e) { throw e; } }
/// <summary> /// 修改服务费低消设置 /// </summary> /// <param name="detail">服务费设置详细</param> /// <param name="serverFeeMode">服务费模式</param> /// <returns>成功则返回true,失败返回false</returns> public bool UpdateTableTypeDetail(TableTypeDetail detail) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { detail.UpdateBy = SubjectUtils.GetAuthenticationId(); detail.UpdateDatetime = DateTime.Now; DbEntityEntry<IShow.ChooseDishes.Data.TableTypeDetail> entry = entities.Entry<IShow.ChooseDishes.Data.TableTypeDetail>(detail); entry.State = System.Data.Entity.EntityState.Unchanged; entry.Property("StartMoney").IsModified = true; entry.Property("StartGetMoneyTime").IsModified = true; entry.Property("StartUnit").IsModified = true; entry.Property("StartDateTime").IsModified = true; entry.Property("EndDateTime").IsModified = true; entry.Property("OutMoney").IsModified = true; entry.Property("OutTime").IsModified = true; entry.Property("OutTimeFree").IsModified = true; entry.Property("ServerfreeNax").IsModified = true; entry.Property("ServerfreeAccountType").IsModified = true; entry.Property("ServerfreeNum").IsModified = true; entry.Property("Rate").IsModified = true; entry.Property("ConsumerMode").IsModified = true; entry.Property("ConsumerMoney").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; entry.Property("UpdateBy").IsModified = true; //entry.Property("TableTypeDetailId").IsModified = false; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = false; if (result == 1) { return true; } else { return false; } } } catch (Exception e) { throw e; } }
/**删除桌类,逻辑删除**/ public void DeleteTableType(int typeId) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { //检查是否被餐桌关联 List<IShow.ChooseDishes.Data.Table> tableList = LoadTableByTypeId(typeId); if (tableList != null && tableList.Count > 0) { throw new ServiceException("该餐桌类别关联了餐桌,不能删除!"); } TableType type = new TableType(); type.TableTypeId = typeId; type.Deleted = 1; DbEntityEntry<TableType> entry = entities.Entry<TableType>(type); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Deleted").IsModified = true; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { throw new ServiceException("修改失败!"); } } } catch (Exception e) { throw new ServiceException(e.Message); } }
public void UpdateTableType(TableType type) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DbEntityEntry<TableType> entry = entities.Entry<TableType>(type); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Name").IsModified = true; entry.Property("PeopleMin").IsModified = true; entry.Property("PeopleMax").IsModified = true; entry.Property("PriceType").IsModified = true; entry.Property("ServerfreeModel").IsModified = true; entry.Property("ColorType").IsModified = true; entry.Property("UpdateBy").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; entry.Property("LowConsCalcType").IsModified = true; entry.Property("ServerFeeCalcType").IsModified = true; entry.Property("CanDiscount").IsModified = true; entry.Property("InLowConsume").IsModified = true; try { entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; } catch (Exception e) { throw new ServiceException(e.Message); } } }
//删除道菜明细 /// <summary> /// /// </summary> /// <param name="Id"> 0按主键ID删除,1,按道菜编号删除</param> /// <param name="Type"></param> /// <returns></returns> public int delDishDetail(int Id,int Type) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Expression<Func<DishDetail, bool>> checkCourse = Detail => Detail.DishDetailId == Id&&Detail.Deleted==0; //先查询 后修改 if (Type == 1) { checkCourse = Detail => Detail.DishDaoId == Id && Detail.Deleted == 0; } List<DishDetail> type = entities.DishDetail.Where(checkCourse).ToList(); if (type != null&&type.Count>0) { foreach (var t in type) { t.UpdateBy = SubjectUtils.GetAuthenticationId(); t.UpdateDatetime = DateTime.Now; t.Deleted = 1; //直接修改的方式 DbEntityEntry<DishDetail> entry = entities.Entry<DishDetail>(t); entry.State = System.Data.Entity.EntityState.Modified; //设置修改状态为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; }
/// <summary> /// 根据指定日期删除创建日期比该日期小的日志 /// deleted SystemLog object from table SystemLog where StartDate less than the parameter date /// </summary> /// <param name="date">日期</param> public void DeleteByDate(DateTime date) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { List<SystemLog> _books; _books = entities.SystemLog.Where(book => book.CreateDatetime.CompareTo(date)<0).ToList(); if(_books!=null) foreach (var bk in _books) { DbEntityEntry<SystemLog> entry = entities.Entry<SystemLog>(bk); entry.State = EntityState.Deleted; } entities.SaveChanges(); } }
public bool DeleteRawMaterial(int id) { if (id < 0) { return false; } using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { RawMaterial booktype = new RawMaterial() { Id = id, }; DbEntityEntry<RawMaterial> entry = entities.Entry<RawMaterial>(booktype); entry.State = EntityState.Deleted; entities.SaveChanges(); return true; } catch (Exception e) { e.ToString(); return false; } } }
//根据做法类型编码删除菜品做法类型,如果删除失败返回false,如果删除成功,则返回true public bool DeleteDishesWayNameByCode(int id) { if (id == null) { return false; } //先判断是否存在有做法,如果有做法,则不能返回false DishesWayDataService odws = new DishesWayDataService(); List<DischesWay> orgDischesWay = odws.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 bool UpdateType(DishType type) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DbEntityEntry<DishType> entry = entities.Entry<DishType>(type); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Name").IsModified = true; entry.Property("DishTypeId").IsModified = false; //TODO 如果更新状态为“删除”则要检查是否关联了菜品 try { entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return true; } else { return false; } } catch (Exception e) { Console.WriteLine(e.ToString()); return false; } } } catch (Exception e) { throw e; } }