public void AddorUpdate(ResourceDto dto) { var entity = dto.MapTo <Resource>(); //var query = _resourceRepository.GetAllAsNoTracking(); //var model = query.SingleOrDefault(p => p.Id == entity.Id); 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; _resourceRepository.Update(model); } }
/// <summary> /// 转换为资源实体 /// </summary> /// <param name="dto">资源数据传输对象</param> public static Resource ToEntity(this ResourceDto dto) { if (dto == null) { return(new Resource()); } return(dto.MapTo(new Resource(dto.Id.ToGuid(), "", 1))); }
public static VmResourceTreeGrid ToTreeGridVm(this ResourceDto dto) { VmResourceTreeGrid vmRoleGrid = dto.MapTo <VmResourceTreeGrid>(); vmRoleGrid.Type = dto.Type.ToString(); vmRoleGrid.CreationTime = dto.CreationTime.ToChineseDateTimeString(); vmRoleGrid.attributes = new { url = vmRoleGrid.Uri }; return(vmRoleGrid); }
public void AddorUpdate(ResourceDto dto) { _resourceDomainService.AddorUpdate(dto.MapTo <Resource>()); }