mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-18 23:42:28 +00:00
* Initial commit to support developer slots * Remove hearting story levels, prevent race condition in adding dev slots, and remove LastContactHelper local db object. * Fix photos taken in pod showing wrong level. * Add support for pod and create mode photos * Add time display to photos and added photo display to level page * Add pagination to in game photos * Update in pod description * Fix migration * Adjust wording of photos taken on local slots * Set slot default type to User Fixes old slots being set to developer slots * Apply suggestions * Add player count to developer slots Co-authored-by: Jayden <jvyden@jvyden.xyz>
52 lines
No EOL
1.8 KiB
C#
52 lines
No EOL
1.8 KiB
C#
#nullable enable
|
|
using LBPUnion.ProjectLighthouse.Configuration;
|
|
using LBPUnion.ProjectLighthouse.PlayerData;
|
|
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
|
using LBPUnion.ProjectLighthouse.Types;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
|
|
|
|
public class PhotosPage : BaseLayout
|
|
{
|
|
|
|
public int PageAmount;
|
|
|
|
public int PageNumber;
|
|
|
|
public int PhotoCount;
|
|
|
|
public List<Photo> Photos = new();
|
|
|
|
public string? SearchValue;
|
|
public PhotosPage(Database database) : base(database)
|
|
{}
|
|
|
|
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(name)) name = "";
|
|
|
|
this.SearchValue = name.Replace(" ", string.Empty);
|
|
|
|
this.PhotoCount = await this.Database.Photos.Include
|
|
(p => p.Creator)
|
|
.CountAsync(p => p.Creator!.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue));
|
|
|
|
this.PageNumber = pageNumber;
|
|
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize));
|
|
|
|
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
|
|
|
this.Photos = await this.Database.Photos.Include
|
|
(p => p.Creator)
|
|
.Include(p => p.Slot)
|
|
.Where(p => p.Creator!.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue))
|
|
.OrderByDescending(p => p.Timestamp)
|
|
.Skip(pageNumber * ServerStatics.PageSize)
|
|
.Take(ServerStatics.PageSize)
|
|
.ToListAsync();
|
|
|
|
return this.Page();
|
|
}
|
|
} |