145 lines
4.9 KiB
C#
145 lines
4.9 KiB
C#
using _2021_backend.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.IO.Compression;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _2021_backend.Utils;
|
|
using System.Threading.Tasks;
|
|
using System.Security.Claims;
|
|
|
|
namespace _2021_backend.Pages.Students
|
|
{
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly _2021_backend.Data.BackendContext Context;
|
|
public static int PageSize { get; set; }
|
|
public int PageCount { get; set; }
|
|
public int PageId { get; set; }
|
|
public string errmsg { get; set; }
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public string SearchString { get; set; }
|
|
[BindProperty(SupportsGet = true)]
|
|
public grade Grade { get; set; }
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public string SearchQQ { get; set; }
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public string SearchTel { get; set; }
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public status StatusSel { get; set; } = status.暂缺;
|
|
|
|
|
|
|
|
public IndexModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
public List<Student> Student { get; set; }
|
|
public IActionResult Construct(int pageId, string errInfo)
|
|
{
|
|
PageSize = 30;
|
|
if (string.IsNullOrEmpty(errInfo))
|
|
{
|
|
errmsg = "";
|
|
}
|
|
else
|
|
{
|
|
errmsg = errInfo;
|
|
}
|
|
if (pageId == null) pageId = 0;
|
|
IQueryable<Student> q;
|
|
if (!string.IsNullOrEmpty(SearchString))
|
|
{
|
|
q = Context.Students.Where(s => (s.Name.Contains(SearchString) || s.Stuid.Contains(SearchString)));
|
|
}
|
|
else
|
|
{
|
|
q = Context.Students;
|
|
}
|
|
if (Grade != grade.暂缺) q = q.Where(it => it.Grade == Grade);
|
|
if (StatusSel != status.暂缺) q = q.Where(it => it.Status == StatusSel);
|
|
if (!String.IsNullOrEmpty(SearchTel)) q = q.Where(it => it.Tel.Contains(SearchTel));
|
|
if (!String.IsNullOrEmpty(SearchQQ)) q = q.Where(it => it.Email.Contains(SearchQQ));
|
|
Student = q.ToList();
|
|
|
|
Student.Sort((Student a, Student b) =>
|
|
{
|
|
return -a.RegisterTime.CompareTo(b.RegisterTime);
|
|
});
|
|
int cnt = Student.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;
|
|
Student = Student.GetRange(PageId * PageSize, count);
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAsync(int? pageId, string errInfo)
|
|
{
|
|
if (pageId == null) pageId = 0;
|
|
return Construct((int)pageId, errInfo);
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(int? pageId, string errInfo)
|
|
{
|
|
if (pageId == null) pageId = 0;
|
|
return Construct((int)pageId, errInfo);
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostFinalizeAsync(int? pageId, string errInfo)
|
|
{
|
|
if (HttpContext.User.HasClaim((c) =>
|
|
{
|
|
return c.Type == ClaimTypes.Role && (
|
|
c.Value == "admin" || c.Value == "manager");
|
|
}))
|
|
{
|
|
if (pageId == null) pageId = 0;
|
|
|
|
foreach (var s in Context.Students)
|
|
{
|
|
if (s.RegisterTime.CompareTo(new DateTime(2021, 11, 11)) > 0) s.Status = status.不通过;
|
|
else if (s.Timelist.Count == 0 && s.Status != status.不通过) s.Status = status.需调整时间;
|
|
}
|
|
Context.SaveChanges();
|
|
return Construct((int)pageId, errInfo);
|
|
}
|
|
else
|
|
{
|
|
return Construct(pageId??0, "您无权进行此操作");
|
|
}
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostReselectAllAsync(int? pageId,string errInfo)
|
|
{
|
|
if (HttpContext.User.HasClaim((c) =>
|
|
{
|
|
return c.Type == ClaimTypes.Role && (
|
|
c.Value == "admin" || c.Value == "manager");
|
|
}))
|
|
{
|
|
if (pageId == null) pageId = 0;
|
|
foreach (var s in Context.Students)
|
|
{
|
|
if (s.Status != status.不通过) s.Status = status.需调整时间;
|
|
}
|
|
Context.SaveChanges();
|
|
return Construct((int)pageId, errInfo);
|
|
}
|
|
else
|
|
{
|
|
return Construct(pageId ?? 0, "您无权进行此操作");
|
|
}
|
|
}
|
|
}
|
|
}
|