public void AddorUpdate(Resource entity) { var model = ResourceRepository.Find(entity.Id); Resource resourceParent = entity.ParentId == null ? null : ResourceRepository.Find((Guid)entity.ParentId); if (model == null) { entity.FixPathAndLevel(resourceParent); ResourceRepository.Add(entity); } else { model.FixPathAndLevel(resourceParent); //model.Id = entity.Id; model.ApplicationId = entity.ApplicationId; model.ParentId = entity.ParentId; model.Name = entity.Name; //model.Path = entity.Path; //model.Level = entity.Level; model.SortId = entity.SortId; model.Uri = entity.Uri; model.Type = entity.Type; model.Enabled = entity.Enabled; //model.Version = entity.Version; } }
/// <summary> /// 修正树形数据的物理路径和层级 /// </summary> /// <param name="parent"></param> public void FixPathAndLevel(Resource parent) { if (Equals(parent, null)) { Level = 1; Path = Id.ToString() + ","; return; } Level = parent.Level + 1; Path = string.Format("{0}{1},", parent.Path, Id); }