43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using _2021_backend.Data;
|
|
using _2021_backend.Models;
|
|
|
|
namespace _2021_backend.Pages.Submissions
|
|
{
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly _2021_backend.Data.BackendContext Context;
|
|
|
|
public static int PageSize = 30;
|
|
public int PageCount { get; set; }
|
|
public int PageId { get; set; }
|
|
|
|
public IndexModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
public List<Submission> Submission { get;set; }
|
|
|
|
public async Task OnGetAsync(int pageId)
|
|
{
|
|
var q = from e in Context.Submissions orderby e.SubmitTime select e;
|
|
Submission = await q.ToListAsync();
|
|
Submission.Sort((a,b)=>b.SubmitTime.CompareTo(a.SubmitTime));
|
|
int cnt = Submission.Count;
|
|
PageCount = (int)Math.Ceiling((double)cnt / (double)PageSize);
|
|
if (pageId >= PageCount) pageId = PageCount - 1;
|
|
if (pageId < 0) pageId = 0;
|
|
PageId = (int)pageId;
|
|
int count = (PageId + 1) * PageSize > cnt ? (cnt - PageId * PageSize) : PageSize;
|
|
Submission = Submission.GetRange(PageId * PageSize, count);
|
|
}
|
|
}
|
|
}
|