/// <summary> /// 更新工作分组 /// </summary> /// <param name="newJobGroup">工作分组对象</param> /// <returns>执行结果</returns> static void UpdateJobGroup(JobGroup newJobGroup) { JobGroup jobGroup = jobGroupRepository.Get(QueryFactory.Create <JobGroupQuery>(r => r.Code == newJobGroup.Code)); if (jobGroup == null) { throw new Exception("没有指定要操作的分组信息"); } //上级 string newParentGroupId = newJobGroup.Parent?.Code ?? string.Empty; string oldParentGroupId = jobGroup.Parent?.Code ?? string.Empty; //上级改变后 if (newParentGroupId != oldParentGroupId) { JobGroup parentGroup = null; if (!newParentGroupId.IsNullOrEmpty()) { IQuery parentQuery = QueryFactory.Create <JobGroupQuery>(c => c.Code == newParentGroupId); parentGroup = jobGroupRepository.Get(parentQuery); if (parentGroup == null) { throw new Exception("请选择正确的上级分组"); } } jobGroup.SetParentGroup(parentGroup); } //修改信息 jobGroup.Name = newJobGroup.Name; jobGroup.Remark = newJobGroup.Remark; jobGroup.Save();//保存 }
/// <summary> /// 添加工作分组 /// </summary> /// <param name="jobGroup">工作分组对象</param> /// <returns>执行结果</returns> static void AddJobGroup(JobGroup jobGroup) { #region 级 string parentGroupId = jobGroup.Parent == null ? "" : jobGroup.Parent.Code; JobGroup parentGroup = null; if (!parentGroupId.IsNullOrEmpty()) { IQuery parentQuery = QueryFactory.Create <JobGroupQuery>(c => c.Code == parentGroupId); parentGroup = jobGroupRepository.Get(parentQuery); if (parentGroup == null) { throw new Exception("请选择正确的上级分组"); } } jobGroup.SetParentGroup(parentGroup); #endregion jobGroup.Save();//保存 }