public static AppResourceDto GenerateTree(this IEnumerable <AppResourceDto> source) { AppResourceDto root = null; foreach (AppResourceDto item in source) { if (root == null) { root = item; } if (string.CompareOrdinal(item.Id, root?.Id) < 0) { root = item; } var subRex = new Regex($"{item.Id}\\d\\d$"); List <AppResourceDto> children = source.Where(x => { subRex.IsMatch(x.Id); return(subRex.IsMatch(x.Id)); } ).ToList(); item.Children = children; } return(root); }
public Task AddResourceAsync(AppResourceDto Resource, string parentId) { var newId = this._keyedIdGenerate.NewId(parentId); var new62Id = this._numberConvert.ToString(newId).PadLeft(2, '0'); var appResourceEntity = this._mapper.Map <AppResourceEntity>(Resource); appResourceEntity.Id = Convert.ToInt32(parentId) == 0 ? new62Id : (parentId + new62Id); return(this._resourceRepository.InsertAsync(appResourceEntity)); }
public Task AddResourceAsync(AppResourceDto Resource, string parentId) { var newId = this._keyedIdGenerate.NewId(parentId); var new62Id = this._numberConvert.ToString(newId).PadLeft(2, '0'); var appResourceEntity = this._mapper.Map <AppResourceEntity>(Resource); var success = int.TryParse(parentId, out int result); appResourceEntity.Id = (success && result == 0) ? new62Id : (parentId + new62Id); return(this._resourceRepository.InsertAsync(appResourceEntity)); }
public Task EditAsync(string id, AppResourceDto Resource) { return(this._resourceRepository.UpdateAsync( () => new AppResourceEntity { Describe = Resource.Describe, IconUrl = Resource.IconUrl, Parameters = Resource.Parameters, ResourceCode = Resource.ResourceCode, ResourceName = Resource.ResourceName, ResourceType = Resource.ResourceType, Url = Resource.Url }, x => x.Id == id)); }
public Task EditResource(string id, [FromBody] AppResourceDto resource) { return(this._resourceService.EditAsync(id, resource)); }
public Task AddResource(string parentId, [FromBody] AppResourceDto resource) { return(this._resourceService.AddResourceAsync(resource, parentId)); }