/// <summary> /// 删除一个机构及其所有下级(包括下级人员) /// </summary> /// <param name="orgID"></param> /// <returns></returns> public int DeleteAndAllChilds(Guid orgID) { int i = 0; using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope()) { UsersRelation bur = new UsersRelation(); Users user = new Users(); UsersInfo userInfo = new UsersInfo(); var childs = GetAllChilds(orgID); foreach (var child in childs) { //删除人员及关系 var urs = bur.GetAllByOrganizeID(child.ID); foreach (var ur in urs) { bur.Delete(ur.UserID, ur.OrganizeID); user.Delete(ur.UserID); i += userInfo.Delete(ur.UserID); } i += Delete(child.ID); } //删除人员及关系 var urs1 = bur.GetAllByOrganizeID(orgID); foreach (var ur in urs1) { bur.Delete(ur.UserID, ur.OrganizeID); user.Delete(ur.UserID); i += userInfo.Delete(ur.UserID); } i += Delete(orgID); scope.Complete(); } return(i); }
public int DeleteAndAllChilds(Guid orgID) { int num = 0; using (TransactionScope transactionScope = new TransactionScope()) { UsersRelation usersRelation = new UsersRelation(); Users users = new Users(); List <RoadFlow.Data.Model.Organize> allChilds = GetAllChilds(orgID); List <string> list = new List <string>(); List <RoadFlow.Data.Model.Organize> list2 = new List <RoadFlow.Data.Model.Organize>(); foreach (RoadFlow.Data.Model.Organize item in allChilds) { foreach (RoadFlow.Data.Model.UsersRelation item2 in usersRelation.GetAllByOrganizeID(item.ID).FindAll((RoadFlow.Data.Model.UsersRelation p) => p.IsMain == 1)) { RoadFlow.Data.Model.Users users2 = users.Get(item2.UserID); usersRelation.Delete(item2.UserID, item2.OrganizeID); num += users.Delete(item2.UserID); if (users2 != null) { list.Add(users2.Account); } } num += Delete(item.ID); list2.Add(item); } foreach (RoadFlow.Data.Model.UsersRelation item3 in usersRelation.GetAllByOrganizeID(orgID).FindAll((RoadFlow.Data.Model.UsersRelation p) => p.IsMain == 1)) { usersRelation.Delete(item3.UserID, item3.OrganizeID); num += users.Delete(item3.UserID); RoadFlow.Data.Model.Users users3 = users.Get(item3.UserID); if (users3 != null) { list.Add(users3.Account); } } num += Delete(orgID); RoadFlow.Data.Model.Organize organize = Get(orgID); if (organize != null) { list2.Add(organize); } if (RoadFlow.Platform.WeiXin.Config.IsUse) { RoadFlow.Platform.WeiXin.Organize organize2 = new RoadFlow.Platform.WeiXin.Organize(); if (list.Count > 0) { organize2.DeleteUserAsync(list.ToArray()); } foreach (RoadFlow.Data.Model.Organize item4 in list2) { organize2.DeleteDeptAsync(item4.IntID); } } transactionScope.Complete(); return(num); } }
public int DeleteAndAllChilds(Guid orgID) { int num = 0; using (TransactionScope transactionScope = new TransactionScope()) { UsersRelation usersRelation1 = new UsersRelation(); Users users1 = new Users(); List <RoadFlow.Data.Model.Organize> allChilds = this.GetAllChilds(orgID); List <string> stringList = new List <string>(); List <RoadFlow.Data.Model.Organize> organizeList = new List <RoadFlow.Data.Model.Organize>(); foreach (RoadFlow.Data.Model.Organize organize in allChilds) { foreach (RoadFlow.Data.Model.UsersRelation usersRelation2 in usersRelation1.GetAllByOrganizeID(organize.ID).FindAll((Predicate <RoadFlow.Data.Model.UsersRelation>)(p => p.IsMain == 1))) { RoadFlow.Data.Model.Users users2 = users1.Get(usersRelation2.UserID); usersRelation1.Delete(usersRelation2.UserID, usersRelation2.OrganizeID); num += users1.Delete(usersRelation2.UserID); if (users2 != null) { stringList.Add(users2.Account); } } num += this.Delete(organize.ID); organizeList.Add(organize); } foreach (RoadFlow.Data.Model.UsersRelation usersRelation2 in usersRelation1.GetAllByOrganizeID(orgID).FindAll((Predicate <RoadFlow.Data.Model.UsersRelation>)(p => p.IsMain == 1))) { usersRelation1.Delete(usersRelation2.UserID, usersRelation2.OrganizeID); num += users1.Delete(usersRelation2.UserID); RoadFlow.Data.Model.Users users2 = users1.Get(usersRelation2.UserID); if (users2 != null) { stringList.Add(users2.Account); } } num += this.Delete(orgID); RoadFlow.Data.Model.Organize organize1 = this.Get(orgID); if (organize1 != null) { organizeList.Add(organize1); } if (RoadFlow.Platform.WeiXin.Config.IsUse) { RoadFlow.Platform.WeiXin.Organize organize2 = new RoadFlow.Platform.WeiXin.Organize(); if (stringList.Count > 0) { organize2.DeleteUserAsync(stringList.ToArray()); } foreach (RoadFlow.Data.Model.Organize organize3 in organizeList) { organize2.DeleteDeptAsync(organize3.IntID); } } transactionScope.Complete(); } return(num); }