/// <summary> /// 拖拽排序(拖拽完就保存) /// </summary> /// <param name="new_prev_order">拖拽后上节点排序值</param> /// <param name="currDisciplineId">当前被拖拽ID</param> /// <param name="currParentId">当前被拖拽ID的父ID</param> /// <returns></returns> public bool MoveDiscipline(SortDisciplineModel model, int System_Station_ID) { SqlMapper.BeginTransaction(); try { W_Discipline disModel = Orm.Single <W_Discipline>(x => x.ID == model.currDisciplineId && x.System_Station_ID == System_Station_ID); if (disModel == null) { throw new ApiException("请刷新重试,您要操作的数据不存在"); } if (model.currParentId == 0) { SqlMapper.Update("MoveIDDiscipline", new { new_prev_order = model.new_prev_order, currParentId = 0, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }); } else if (model.currParentId > 0) { SqlMapper.Update("MoveIDDiscipline", new { currParentId = model.currParentId, new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }); } SqlMapper.CommitTransaction(); return(true); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw ex; } }
/// <summary> /// 禁用、启用学科 /// </summary> public bool SetDisciplineValid(W_Discipline model, int System_Station_ID) { SqlMapper.BeginTransaction(); try { if (model.ID < 0) { throw new ApiException("无效参数"); } W_Discipline modelDiscipline = Orm.Single <W_Discipline>(x => x.ID == model.ID && x.System_Station_ID == System_Station_ID); if (modelDiscipline == null) { throw new ApiException("操作失败,您无权操作!"); } if (model.Valid == 1) { if (modelDiscipline.CID != 0) { W_Discipline CidModel = Orm.Single <W_Discipline>(x => x.ID == modelDiscipline.CID && x.System_Station_ID == System_Station_ID); if (CidModel.Valid == 0) { throw new ApiException("请先启用上级学科!"); } } modelDiscipline.Valid = model.Valid; if (Orm.Update(modelDiscipline) <= 0) { throw new ApiException("修改失败"); } } else { List <W_Discipline> DisModel = SqlMapper.QueryForList <W_Discipline>("GetDisciplineValid", new { ID = modelDiscipline.ID, System_Station_ID = System_Station_ID }).ToList(); if (DisModel != null && DisModel.Count > 0) { DisModel.ForEach(X => { SqlMapper.Update("UpdateDisciplineValid", new { ID = X.ID, Valid = model.Valid, System_Station_ID = System_Station_ID }); GetDiscipline_ChildSetValid(X.ID, model.Valid, System_Station_ID); }); } modelDiscipline.Valid = model.Valid; if (Orm.Update(modelDiscipline) <= 0) { throw new ApiException("操作失败"); } } SqlMapper.CommitTransaction(); return(true); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw ex; } }
/// <summary> ///删除学科及对应的关系表 DeleteDiscipline /// </summary> public bool RemoveDiscipline(int ID, int System_Station_ID) { if (ID <= 0) { throw new ApiException("无效参数!"); } //判断是不是该机构添加的学科 W_Discipline model = Orm.Single <W_Discipline>(x => x.ID == ID && x.System_Station_ID == System_Station_ID); if (model == null) { throw new ApiException("操作失败,未找到对应的数据!"); } ///判断学科启用状态 if (model.Valid == 1) { throw new ApiException("学科启用状态,不能删除!"); } W_Discipline modelCid = Orm.Single <W_Discipline>(x => x.CID == ID && x.System_Station_ID == System_Station_ID); ///判断学科子集是否存在课程 if (modelCid != null) { throw new ApiException("该学科下面存在课程,不能删除!"); } W_QuestionStore modelstore = Orm.Single <W_QuestionStore>(x => x.Discipline_ID == ID && x.System_Station_ID == System_Station_ID && x.IsDelete == 0); ///判断题库是否应用该学科 if (modelstore != null) { throw new ApiException("题库应用了该学科,不能删除!"); } W_CourseWare modelware = Orm.Single <W_CourseWare>(x => x.Discipline_ID == ID && x.System_Station_ID == System_Station_ID); ///判断资源库是否应用该学科 if (modelware != null) { throw new ApiException("资源库应用了该学科,不能删除!"); } //删除数据 if (Orm.Delete <W_Discipline>(x => x.ID == ID && x.System_Station_ID == System_Station_ID) > 0) { return(true); } return(false); }
/// <summary> /// 是否推荐学科 /// </summary> /// <param name="ID"></param> /// <param name="System_Station_ID"></param> /// <returns></returns> public bool GetIsRecommend(int ID, int Recommend, int System_Station_ID) { W_Discipline model = Orm.Single <W_Discipline>(x => x.ID == ID && x.System_Station_ID == System_Station_ID); if (model == null) { throw new ApiException("学科已删除,请重试"); } if (Recommend == 1) { model.IsRecommend = 1; } else { model.IsRecommend = 0; } if (Orm.Update(model) <= 0) { throw new ApiException("操作失败,请重试"); } return(true); }
/// <summary> ///添加 or 修改学科 /// </summary> public dynamic SaveDiscipline(W_Discipline Model, int System_Station_ID, int AccountID) { if (Model.ID > 0) { //判断是不是该机构添加的学科 W_Discipline model = Orm.Single <W_Discipline>(x => x.ID == Model.ID && x.System_Station_ID == System_Station_ID); Model.AddPerson = model.AddPerson; Model.AddTime = model.AddTime; Model.Valid = model.Valid; Model.System_Station_ID = model.System_Station_ID; Model.Orders = model.Orders; if (model == null) { throw new ApiException("操作失败,未找到对应的数据!"); } if (Orm.Update(Model) > 0) { return(true); } else { return(false); } } else { Model.AddPerson = AccountID; Model.AddTime = DateTime.Now; Model.Valid = 1; Model.System_Station_ID = System_Station_ID; int MaxOrders = SqlMapper.QueryForObject <int>("GetMaxOrders", new { CID = Model.CID, System_Station_ID = System_Station_ID }); Model.Orders = MaxOrders + 1; int a = (int)Orm.Insert(Model, true); return(Orm.Single <W_Discipline>(x => x.ID == a && x.System_Station_ID == System_Station_ID)); } }
public dynamic SetDisciplineValid(W_Discipline Model) { return(Success(mapper.SetDisciplineValid(Model, this.System_Station_ID))); }
public dynamic SaveDiscipline(W_Discipline Model) { return(Success(mapper.SaveDiscipline(Model, this.System_Station_ID, this.AccountID))); }
/// <summary> /// 拖拽排序(拖拽完就保存) /// </summary> /// <param name="old_prev_order">拖拽前上节点排序值</param> /// <param name="old_next_order">拖拽前下节点排序值</param> /// <param name="new_prev_order">拖拽后上节点排序值</param> /// <param name="new_next_order">拖拽后下节点排序值</param> /// <param name="currDisciplineId">当前被拖拽ID</param> /// <param name="currParentId">当前被拖拽ID的父ID</param> /// <param name="System_Station_ID">系统ID</param> /// <returns></returns> public bool SortDiscipline(SortDisciplineModel model, int System_Station_ID) { SqlMapper.BeginTransaction(); try { W_Discipline Disciplinemodel = Orm.Single <W_Discipline>(x => x.ID == model.currDisciplineId && x.System_Station_ID == System_Station_ID); if (model.new_prev_order == model.old_prev_order && model.new_next_order == model.old_next_order) //没移动 { return(false); } if (model.new_prev_order == 0) //第一种情况:拖到最上面 (拖拽后上一层order为0) { Disciplinemodel.Orders = 1; if (Orm.Update(Disciplinemodel) > 0) { if (model.old_next_order == 0) //从最下面拖到最上面 { SqlMapper.Update("SortDiscipline", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline1", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, old_next_order = model.old_next_order, currDisciplineId = model.currDisciplineId }); } } } else if (model.new_next_order == 0)//第二种情况:拖到最下面(拖拽后下一层order为0) { if (SqlMapper.Update("SortDiscipline2", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, currDisciplineId = model.currDisciplineId }) > 0) { if (model.old_prev_order == 0) //从最上面拖到最下面 { SqlMapper.Update("SortDiscipline3", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline4", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, old_prev_order = model.old_prev_order, currDisciplineId = model.currDisciplineId }); } } } else if (model.new_prev_order > 0 && model.new_next_order > 0) //第三种情况:拖到中间 { if (model.new_prev_order < model.old_prev_order && model.new_next_order < model.old_next_order) //往上拖 { if (SqlMapper.Update("SortDiscipline5", new { new_next_order = model.new_next_order, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }) > 0) { if (model.old_next_order == 0) //从最下面往上拖 { SqlMapper.Update("SortDiscipline6", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline7", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, old_next_order = model.old_next_order, new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId }); } } } else if (model.new_prev_order > model.old_prev_order && model.new_next_order > model.old_next_order)//往下拖 { if (SqlMapper.Update("SortDiscipline8", new { new_prev_order = model.new_prev_order, currDisciplineId = model.currDisciplineId, System_Station_ID = System_Station_ID }) > 0) { if (model.old_prev_order == 0) //从最上面往下拖 { SqlMapper.Update("SortDiscipline9", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, new_next_order = model.new_next_order, currDisciplineId = model.currDisciplineId }); } else { SqlMapper.Update("SortDiscipline10", new { currParentId = model.currParentId, System_Station_ID = System_Station_ID, new_next_order = model.new_next_order, old_prev_order = model.old_prev_order, currDisciplineId = model.currDisciplineId }); } } } } SqlMapper.CommitTransaction(); return(true); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw ex; } }