diff --git a/MiniIndex/Pages/Minis/Details.cshtml b/MiniIndex/Pages/Minis/Details.cshtml index 8705f79..80232a9 100644 --- a/MiniIndex/Pages/Minis/Details.cshtml +++ b/MiniIndex/Pages/Minis/Details.cshtml @@ -1,4 +1,5 @@ @page +@using MiniIndex.Models; @model MiniIndex.Pages.Minis.DetailsModel @inject SignInManager SignInManager @{ @@ -42,8 +43,6 @@

@Html.DisplayFor(model => model.Mini.Name) by @Html.DisplayFor(model => model.Mini.Creator.Name)


- -
@@ -127,7 +126,6 @@ }
-
@@ -147,19 +145,18 @@
- @if (User.IsInRole("Moderator") && Model.SimilarTags.Count > 0) + @if (User.IsInRole("Moderator") && Model.RecommendedTags.Any()) {

Recommended Tags

- @foreach (var Tag in Model.SimilarTags) + @foreach (var Tag in Model.RecommendedTags) { + @Tag.TagName }
-
+
} -

Genre

@foreach (var Tag in Model.UnusedTags.Where(m => m.Category.ToString() == "Genre")) @@ -179,12 +176,12 @@ @{var PreviousCategory = "";}
- - @foreach (var Tag in Model.UnusedTags.Where(m => !string.IsNullOrEmpty(m.Category.ToString()) - && m.Category.ToString() != "Genre" - && m.Category.ToString() != "OtherDescription" - && m.Category.ToString() != "CreatureName" - && m.Category.ToString() != "Use")) + @foreach (var Tag in Model.UnusedTags + .Where(m => !string.IsNullOrEmpty(m.Category.ToString()) + && m.Category != TagCategory.Genre + && m.Category != TagCategory.OtherDescription + && m.Category != TagCategory.CreatureName + && m.Category != TagCategory.Use)) { @if (Tag.Category.ToString() != PreviousCategory) { @@ -219,10 +216,7 @@ }
+ Add as new tag -
} - - \ No newline at end of file diff --git a/MiniIndex/Pages/Minis/Details.cshtml.cs b/MiniIndex/Pages/Minis/Details.cshtml.cs index e68c86f..8ec133e 100644 --- a/MiniIndex/Pages/Minis/Details.cshtml.cs +++ b/MiniIndex/Pages/Minis/Details.cshtml.cs @@ -28,7 +28,7 @@ public DetailsModel(UserManager userManager, MiniIndexContext cont public List UnusedTags { get; set; } public List MiscTags { get; set; } public List WordMatchingTags { get; set; } - public List SimilarTags { get; set; } + public List RecommendedTags { get; set; } public bool IsStarred { get; set; } public async Task OnGetAsync(int? id) @@ -73,29 +73,26 @@ public async Task OnGetAsync(int? id) if (User.IsInRole("Moderator")) { - string[] NameSplit = Mini.Name.ToLower().Split(' '); + string[] nameSplit = Mini.Name.ToUpperInvariant().Split(' '); - WordMatchingTags = _context.Tag - .Where(t => NameSplit.Contains(t.TagName.ToLower())) + RecommendedTags = UnusedTags + .Where(t => nameSplit.Contains(t.TagName.ToUpperInvariant())) .ToList(); - //TODO - I'm sure someone who knows LINQ could clean this up a lot. - if (WordMatchingTags.Count > 0) - { - List SimilarMinis = _context.Mini - .Include(m => m.MiniTags) - .ThenInclude(mt => mt.Tag) - .AsEnumerable() - .Where(m => m.MiniTags.Select(mt => mt.Tag).Intersect(WordMatchingTags).Any()) - .ToList(); - - List SimilarMiniTags = SimilarMinis.SelectMany(m => m.MiniTags).ToList(); - SimilarTags = SimilarMiniTags.GroupBy(mt => mt.Tag).Select(grp => grp.First().Tag).Except(Mini.MiniTags.Select(mt => mt.Tag)).ToList(); - } - else - { - SimilarTags = new List(); - } + //if (WordMatchingTags.Count > 0) + //{ + // var similarlyTaggedMinis = await _context.Set() + // .Where(m => m.ID != id) + // .Select(m => new + // { + // mini = m, + // matchingTags = m.MiniTags.Where(mt => WordMatchingTags.Contains(mt.Tag)).Count() + // }) + // .Where(x => x.matchingTags > 0) + // .OrderBy(x => x.matchingTags) + // .Select(x => x.mini) + // .ToListAsync(); + //} } return Page();