public ResourceItem(GetAllResourcesResult res, GetAllResourcesResult[] allResources) { InitializeComponent(); _allResources = allResources; ResourceId = res.Id; currentResource = res; ResourceName.Text = res.Name; ResourceDescription.Text = res.Description; }
public async Task <GetAllResourcesResult[]> GetResources(UseFiltersRequest filter) { var resources = (await Redis.HashKeysAsync(ResourcesName)).Select(k => k.ToString()).ToList(); RedisValue response; if (filter.Id.HasValue) { response = await Redis.HashGetAsync(ResourcesName, filter.Id); if (response.HasValue) { GetAllResourcesResult result = Unpack <GetAllResourcesResult>(response.ToString()); result.Id = filter.Id.ToString(); return(new[] { result }); } return(new GetAllResourcesResult[0]); } if (!string.IsNullOrEmpty(filter.Name)) { var filterByName = (await Redis.HashGetAllAsync(Names)) .ToDictionary(f => f.Name.ToString(), f => f.Value.ToString()) .Where(f => f.Value.ToString().ToLowerInvariant().Contains(filter.Name.ToLowerInvariant())) .ToDictionary(x => x.Key, x => x.Value); resources = resources.Where(r => filterByName.Values.Contains(r)).ToList(); } if (filter.CategoryId.HasValue) { response = await Redis.HashGetAsync(CategoriesName, filter.CategoryId.Value.ToString()); if (response.HasValue) { var resourcesInCategory = Unpack <Resources>(response.ToString()).ResourcesIds; resources = resources.Where(r => resourcesInCategory.Contains(r)).ToList(); } else { resources.Clear(); } } if (filter.ResourceGroupId.HasValue) { response = await Redis.HashGetAsync(ResourceGroupsName, filter.ResourceGroupId.Value.ToString()); if (response.HasValue) { var resourcesInGroup = Unpack <Resources>(response.ToString()).ResourcesIds; resources = resources.Where(r => resourcesInGroup.Contains(r)).ToList(); } else { resources.Clear(); } } if (filter.Tags != null && filter.Tags.Length != 0) { var allKeys = await Redis.HashKeysAsync(TagsName); var keys = new List <string>(); foreach (string tag in filter.Tags) { keys.AddRange(allKeys.Where(k => k.ToString().ToLowerInvariant().Contains(tag.ToLowerInvariant())).Select(k => k.ToString())); } var filterByTags = new Dictionary <string, string[]>(); foreach (var key in keys) { response = await Redis.HashGetAsync(TagsName, key); filterByTags.Add(key, Unpack <Resources>(response.ToString()).ResourcesIds.ToArray()); } var resourcesByTags = filterByTags.Select(f => f.Value).ToArray(); for (int i = 0; i < resourcesByTags.GetLength(0) - 1; i++) { resourcesByTags[i + 1] = resourcesByTags[i].Union(resourcesByTags[i + 1]).ToArray(); } if (!resourcesByTags.Any()) { resources.Clear(); } resources = resources.Where(r => resourcesByTags.Last().Contains(r.ToString())).ToList(); } var allResourcesResults = new List <GetAllResourcesResult>(); for (int i = 0; i < resources.Count; i++) { response = await Redis.HashGetAsync(ResourcesName, resources[i]); var res = Unpack <GetAllResourcesResult>(response.ToString()); res.Id = resources[i]; allResourcesResults.Add(res); } return(allResourcesResults.ToArray()); }
public UpdateResource(GetAllResourcesResult resource) { InitializeComponent(); _selectedResource = resource; UniqueIdentifier.Text = _selectedResource.Id; }