From 6dacfc364513c057eaf16c35e2b1e0e0b3ae5b30 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 30 Nov 2021 18:32:28 -0500 Subject: [PATCH] Add SlotCardPartial class --- .../Pages/Partials/SlotCardPartial.cshtml | 74 +++++++++++++++++++ ProjectLighthouse/Pages/SlotsPage.cshtml | 73 +++--------------- 2 files changed, 83 insertions(+), 64 deletions(-) create mode 100644 ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml diff --git a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml new file mode 100644 index 00000000..61fcf25b --- /dev/null +++ b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml @@ -0,0 +1,74 @@ +@using LBPUnion.ProjectLighthouse +@using LBPUnion.ProjectLighthouse.Types +@using Microsoft.EntityFrameworkCore +@model LBPUnion.ProjectLighthouse.Types.Levels.Slot + +@{ + User user = (User)ViewData["User"]; + + await using Database database = new(); + + string slotName = string.IsNullOrEmpty(Model.Name) ? "Unnamed Level" : Model.Name; + + bool isQueued = false; + bool isHearted = false; + + if (user != null) + { + isQueued = await database.QueuedLevels.FirstOrDefaultAsync(h => h.SlotId == Model.SlotId && h.UserId == user.UserId) != null; + + isHearted = await database.HeartedLevels.FirstOrDefaultAsync(h => h.SlotId == Model.SlotId && h.UserId == user.UserId) != null; + } + + string callbackUrl = (string)ViewData["CallbackUrl"]; +} +
+
+

@slotName

+
+ @Model.Hearts + @Model.Plays + @Model.Thumbsup + @Model.Thumbsdown + + @if (Model.GameVersion == GameVersion.LittleBigPlanet1) + { + + @Model.RatingLBP1 + } +
+

+ Created by @Model.Creator?.Username +

+
+
+ @if (user != null) + { + if (isHearted) + { + + + + } + else + { + + + + } + + if (isQueued) + { + + + + } + else + { + + + + } + } +
+
\ No newline at end of file diff --git a/ProjectLighthouse/Pages/SlotsPage.cshtml b/ProjectLighthouse/Pages/SlotsPage.cshtml index 4af2a0bc..f94c1c69 100644 --- a/ProjectLighthouse/Pages/SlotsPage.cshtml +++ b/ProjectLighthouse/Pages/SlotsPage.cshtml @@ -1,7 +1,5 @@ @page "/slots/{pageNumber:int}" -@using LBPUnion.ProjectLighthouse.Types @using LBPUnion.ProjectLighthouse.Types.Levels -@using Microsoft.EntityFrameworkCore @model LBPUnion.ProjectLighthouse.Pages.SlotsPage @{ @@ -13,69 +11,16 @@ @foreach (Slot slot in Model.Slots) { - string slotName = string.IsNullOrEmpty(slot.Name) ? "Unnamed Level" : slot.Name; - - bool isQueued = false; - bool isHearted = false; - - if (Model.User != null) - { - isQueued = await Model.Database.QueuedLevels.FirstOrDefaultAsync(h => h.SlotId == slot.SlotId && h.UserId == Model.User.UserId) != null; - - isHearted = await Model.Database.HeartedLevels.FirstOrDefaultAsync(h => h.SlotId == slot.SlotId && h.UserId == Model.User.UserId) != null; - } -
-
-
-

@slotName

-
- @slot.Hearts - @slot.Plays - @slot.Thumbsup - @slot.Thumbsdown - - @if (slot.GameVersion == GameVersion.LittleBigPlanet1) - { - - @slot.RatingLBP1 - } -
-

- Created by @slot.Creator?.Username -

-
-
- @if (Model.User != null) - { - if (isHearted) - { - - - - } - else - { - - - - } - - if (isQueued) - { - - - - } - else - { - - - - } - } -
-
+ @await Html.PartialAsync("Partials/SlotCardPartial", slot, new ViewDataDictionary(ViewData) + { + { + "User", Model.User + }, + { + "CallbackUrl", $"~/slots/{Model.PageNumber}" + }, + })
}