/// <summary> /// 添加部门 /// </summary> /// <param name="org">The org.</param> /// <returns>System.Int32.</returns> /// <exception cref="System.Exception">未能找到该组织的父节点信息</exception> public int AddOrUpdate(Org org) { if (org.Id == 0) { ChangeModuleCascade(org); _repository.Add(org); } else { _repository.Update(org); } return org.Id; }
public void TestEdit() { //var org = _app.GetAll().FirstOrDefault(); //org.Name = DateTime.Now.ToShortTimeString(); //_app.AddOrUpdate(org); var org1 = new Org { Id = 1, Name = DateTime.Now.ToShortTimeString() }; _app.AddOrUpdate(org1); }
//修改对象的级联ID,生成类似XXX.XXX.X.XX private void ChangeModuleCascade(Org org) { string cascadeId; int currentCascadeId = 1; //当前结点的级联节点最后一位 var sameLevels = _repository.Find(o => o.ParentId == org.ParentId && o.Id != org.Id); foreach (var obj in sameLevels) { int objCascadeId = int.Parse(obj.CascadeId.Split('.').Last()); if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1; } if (org.ParentId != 0) { var parentOrg = _repository.FindSingle(o => o.Id == org.ParentId); if (parentOrg != null) { cascadeId = parentOrg.CascadeId + "." + currentCascadeId; org.ParentName = parentOrg.Name; } else { throw new Exception("未能找到该组织的父节点信息"); } } else { cascadeId = "0." + currentCascadeId; org.ParentName = "根节点"; } org.CascadeId = cascadeId; }
public string AddOrg(Org org) { try { _orgApp.AddOrUpdate(org); } catch (Exception ex) { BjuiResponse.statusCode = "300"; BjuiResponse.message = ex.Message; } return JsonHelper.Instance.Serialize(BjuiResponse); }