Skip to content

Commit

Permalink
Fixed bug with PageCategoryRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
KenticoDevTrev committed Feb 1, 2022
1 parent 210c087 commit 79d0b04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Data;

namespace Generic.Repositories.Implementations
{
Expand All @@ -34,10 +35,11 @@ public PageCategoryRepository(
public async Task<IEnumerable<CategoryItem>> GetCategoriesByNodeAsync(int nodeID)
{
var dictionary = (await GetCategoriesByIdentifiersAsync()).Item1;
if(dictionary.ContainsKey(nodeID))
if (dictionary.ContainsKey(nodeID))
{
return dictionary[nodeID];
} else
}
else
{
return Array.Empty<CategoryItem>();
}
Expand Down Expand Up @@ -76,7 +78,7 @@ private async Task<Tuple<Dictionary<int, IEnumerable<CategoryItem>>, Dictionary<
builder.ObjectType(TreeCategoryInfo.OBJECT_TYPE)
.ObjectType(CategoryInfo.OBJECT_TYPE);

return await _progressiveCache.Load(async cs =>
return await _progressiveCache.LoadAsync(async cs =>
{
if (cs.Cached)
{
Expand All @@ -95,12 +97,14 @@ private async Task<Tuple<Dictionary<int, IEnumerable<CategoryItem>>, Dictionary<
$"{nameof(CategoryInfo.CategoryName)}",
$"{nameof(CategoryInfo.CategoryDisplayName)}"
});
var retriever = await query.GetEnumerableResultAsync(System.Data.CommandBehavior.Default);

var dt = new DataTable();
dt.Load((await query.ExecuteReaderAsync(CommandBehavior.Default)));

// Group into two dictionaries
var items = retriever.Select(x => new PageCategoryItem()
var items = dt.Rows.Cast<DataRow>().Select(x => new PageCategoryItem()
{
NodeID = (int) x[nameof(TreeNode.NodeID)],
NodeID = (int)x[nameof(TreeNode.NodeID)],
Path = (string)x[nameof(TreeNode.NodeAliasPath)],
CategoryItem = new CategoryItem()
{
Expand All @@ -115,7 +119,7 @@ private async Task<Tuple<Dictionary<int, IEnumerable<CategoryItem>>, Dictionary<
var dictionaryByPath = items.GroupBy(x => x.Path).ToDictionary(key => key.Key, value => value.Select(x => x.CategoryItem));
var result = new Tuple<Dictionary<int, IEnumerable<CategoryItem>>, Dictionary<string, IEnumerable<CategoryItem>>>(dictionaryByNodeID, dictionaryByPath);
return result;
}, new CacheSettings(60, $"GetCategoriesByIdentifiersAsync"));
}, new CacheSettings(60, $"GetCategoriesByIdentifiersAsync"));
}
}

Expand Down
1 change: 1 addition & 0 deletions MVC/MVC.Models/MVC.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Generic</RootNamespace>
<AssemblyName>pository</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 79d0b04

Please sign in to comment.