public static DbEntity ToDbModel(this TEntity item1, bool onlyself = false) { if (item1 == null) { return(null); } var item2 = new DbEntity(); item2.Id = item1.Id; item2.Abutment_Id = item1.Abutment_Id; item2.Name = item1.Name; if (onlyself == false) { item2.Parent = item1.Parent.ToDbModel(true); } item2.ParentId = item1.ParentId; item2.ShowOrder = item1.ShowOrder; item2.Type = (DepartType)item1.Type; item2.Description = item1.Description; if (onlyself == false) { item2.Children = item1.Children.ToDbModel(onlyself); } item2.LeafNodes = item1.LeafNodes.ToDbModel(); return(item2); }
private static void SetNull(DbEntity depDep) { if (depDep.Children != null && depDep.Children.Count == 0) { depDep.Children = null; } if (depDep.LeafNodes != null && depDep.LeafNodes.Count == 0) { depDep.LeafNodes = null; } }
private List <DbModel.Location.Person.Personnel> GetLeafNodes(DbEntity entity) { if (entity != null) { var list = db.Personnels.GetListByPid(entity.Id); entity.LeafNodes = list; return(list); } else { return(new List <DbModel.Location.Person.Personnel>()); } }
private List <DbEntity> GetChildren(DbEntity item) { if (item != null) { var list = dbSet.FindListByPid(item.Id); item.Children = list; return(list); } else { return(new List <DbEntity>()); } }
private void GetChildrenTree(DbEntity entity) { if (entity == null) { return; } var list = GetChildren(entity); if (list != null) { foreach (var item in list) { GetChildrenTree(item); } } }
public TEntity GetEntity(string id) { DbEntity depDep = dbSet.Find(id.ToInt()); SetNull(depDep); if (depDep.Children != null) { foreach (var subDep in depDep.Children) //子部门 { subDep.Parent = null; //切除关联防止序列化出错 subDep.Children = null; //切除关联防止序列化出错 SetNull(subDep); } } TEntity dep = depDep.ToTModel(); return(dep); }
public static TEntity ToTModel(this DbEntity item1, bool onlyself = false) { try { if (item1 == null) { return(null); } var item2 = new TEntity(); item2.Id = item1.Id; item2.Abutment_Id = item1.Abutment_Id; item2.Name = item1.Name; if (onlyself == false) { item2.Parent = item1.Parent.ToTModel(true); } item2.ParentId = item1.ParentId; item2.ShowOrder = item1.ShowOrder; item2.Type = (int)item1.Type; item2.Description = item1.Description; if (onlyself == false) { item2.Children = item1.Children.ToTModel(onlyself); } if (onlyself == false) { item2.LeafNodes = item1.LeafNodes.ToTModel(); } return(item2); } catch (System.Exception ex) { LogEvent.Error(ex); return(null); } }