/// <summary> /// 改变字典排序 /// </summary> /// <param name="orders"></param> /// <param name="adminMenu"></param> /// <returns></returns> public bool UpdateOptionOrders(int orders, Sys_Option adminMenu) { //防止使排序需要为正整数 if (orders <= 0) { orders = 1; } bool isNeedCommit = false; _repository.BeginTran(); try { var maxOrder = _repository.GetMaxValue <Sys_Option>(p => p.GroupKey == adminMenu.GroupKey, p => p.Orders); if (adminMenu.Orders > maxOrder) { adminMenu.Orders = maxOrder + 1; //保证更新的排序不会大于(最大值+1) } if (adminMenu.Orders > orders) //上移排序 { if (UpdateOrderByPlus(adminMenu.GroupKey, orders, adminMenu.Orders) > 0) //上移排序需要将排在自己前面的排序往下移1 { isNeedCommit = true; adminMenu.Orders = orders; if (!UpdateColumns(c => new { c.Orders }, adminMenu)) { isNeedCommit = false; } } } else if (adminMenu.Orders < orders) //下移排序 { if (UpdateOrderBySub(adminMenu.GroupKey, adminMenu.Orders, orders) > 0) //下移排序需要将排在自己后面的排序往上移1 { isNeedCommit = true; adminMenu.Orders = orders; if (!UpdateColumns(c => new { c.Orders }, adminMenu)) { isNeedCommit = false; } } } if (isNeedCommit) { _repository.CommitTran(); } else { _repository.RollBackTran(); } return(isNeedCommit); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { _repository.RollBackTran(); return(false); } }
/// <summary> /// 添加字典 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddOption(Sys_Option model) { //防止使排序需要为正整数 if (model.Orders <= 0) { model.Orders = 1; } bool isNeedCommit = false; _repository.BeginTran(); try { var maxOrder = _repository.GetMaxValue <Sys_Option>(p => p.GroupKey == model.GroupKey, p => p.Orders); if (model.Orders > maxOrder) { model.Orders = maxOrder + 1;//保证更新的排序不会大于(最大值+1) if (_repository.Insert(model) > 0) { isNeedCommit = true; } } else { if (UpdateOrderByPlus(model.GroupKey, model.Orders) > 0)//上移排序需要将排在自己前面的排序往下移1 { isNeedCommit = true; if (_repository.Insert(model) <= 0) { isNeedCommit = false; } } } if (isNeedCommit) { _repository.CommitTran(); } else { _repository.RollBackTran(); } return(isNeedCommit); } catch (Exception ex) { _repository.RollBackTran(); return(false); } }
public bool UpdateColumns(Expression <Func <Sys_Option, object> > columns, Sys_Option model, bool isLock = false) { return(_repository.UpdateColumns(columns, model, isLock) > 0); }
public bool Update(Sys_Option model) { return(_repository.Update(model) > 0); }
public int Insert(Sys_Option model) { return(_repository.Insert(model)); }