206 lines
8.1 KiB
C#
206 lines
8.1 KiB
C#
using _2021_backend.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace _2021_backend.Pages.Students
|
|
{
|
|
public class DetailsModel : PageModel
|
|
{
|
|
public _2021_backend.Data.BackendContext Context;
|
|
|
|
public DetailsModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
[BindProperty]
|
|
public Student Student { get; set; }
|
|
|
|
[BindProperty]
|
|
public int score { get; set; }
|
|
public List<Session> Sessions { get; set; }
|
|
|
|
public List<Submission> Submissions { get; set; }
|
|
|
|
public List<Comment> CurComments { get; set; }
|
|
public Session Interviewtime { get; set; }
|
|
public Comment CommentSample { get; set; }
|
|
public Submission SubmissionSample { get; set; }
|
|
[Display(Name = "评论内容")]
|
|
[BindProperty]
|
|
[Required(ErrorMessage = "该项不能为空")]
|
|
public string NewComment { get; set; }
|
|
|
|
public List<SMS> Messages { get; set; }
|
|
|
|
public IActionResult Construct(string? idstr)
|
|
{
|
|
if (idstr == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
int id = int.Parse(idstr);
|
|
Student = Context.Students.Find(id);
|
|
if (Student == null)
|
|
{
|
|
Console.WriteLine("Student not found.");
|
|
return NotFound();
|
|
}
|
|
Sessions = new List<Session>();
|
|
Submissions = new List<Submission>();
|
|
Interviewtime = Context.Sessions.Find(Student.InterviewTime);
|
|
foreach (var it in Student.Timelist)
|
|
{
|
|
var tm = Context.Sessions.Find(it);
|
|
if (tm == null) Console.WriteLine("null encountered in timelist!");
|
|
Sessions.Add(tm);
|
|
}
|
|
Messages = Context.SMS.Where(it => it.Host == id).ToList();
|
|
CurComments = Context.Comments.Where(cmt => cmt.Student == Student.Id).ToList();
|
|
Sessions.Sort((Session a, Session b) => {
|
|
var x = a.Day.CompareTo(b.Day);
|
|
var y = a.BeginTime.CompareTo(b.BeginTime);
|
|
var z = a.Place.CompareTo(b.Place);
|
|
return (x != 0 ? x : y != 0 ? y : z != 0 ? z : 0);
|
|
|
|
});
|
|
Console.WriteLine("Page construction finished.");
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAsync(string? idstr)
|
|
{
|
|
Console.WriteLine("getting student " + idstr);
|
|
return Construct(idstr);
|
|
}
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(NewComment))
|
|
{
|
|
var cmt = new Comment();
|
|
cmt.Student = Student.Id;
|
|
cmt.Content = NewComment;
|
|
cmt.Operator = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value);
|
|
var stu = Context.Students.Find(Student.Id);
|
|
stu.Comments.Add(cmt.Id);
|
|
Context.Comments.Add(cmt);
|
|
Context.SaveChanges();
|
|
}
|
|
Construct(Student.Id.ToString());
|
|
return RedirectToPage(new { idstr = Student.Id.ToString() });
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAcceptAsync()
|
|
{
|
|
Student = Context.Students.Find(Student.Id);
|
|
Student.Status = status.通过;
|
|
Context.SaveChanges();
|
|
CurComments = Context.Comments.Where(cmt => cmt.Student == Student.Id).ToList();
|
|
Messages = Context.SMS.Where(it => it.Host == Student.Id).ToList();
|
|
Construct(Student.Id.ToString());
|
|
return RedirectToPage(new { idstr = Student.Id.ToString() });
|
|
}
|
|
|
|
|
|
|
|
public async Task<IActionResult> OnPostRejectAsync()
|
|
{
|
|
Student = Context.Students.Find(Student.Id);
|
|
Student.Status = status.不通过;
|
|
Context.SaveChanges();
|
|
Student.Score = 0;
|
|
CurComments = Context.Comments.Where(cmt => cmt.Student == Student.Id).ToList();
|
|
Messages = Context.SMS.Where(it => it.Host == Student.Id).ToList();
|
|
Construct(Student.Id.ToString());
|
|
return RedirectToPage(new { idstr = Student.Id.ToString() });
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostSelectAsync(int stu, int time)
|
|
{
|
|
var st = Context.Students.Find(stu);
|
|
if (st != null)
|
|
{
|
|
|
|
if (Context.Sessions.Any(it => it.Id == time))
|
|
{
|
|
var tm = Context.Sessions.Find(time);
|
|
if (tm.Students.Count < tm.Capacity)
|
|
{
|
|
if (st.InterviewTime != 0)
|
|
{
|
|
var tmold = Context.Sessions.Find(st.InterviewTime);
|
|
if (tmold != null)
|
|
{
|
|
tmold.Students.RemoveAll(it => it == st.Id);
|
|
Context.SaveChanges();
|
|
}
|
|
}
|
|
tm.Students.Add(stu);
|
|
st.InterviewTime = time;
|
|
if (st.Status != status.不通过 && st.Status != status.通过) st.Status = status.已选时间;
|
|
Context.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostPullAsync()
|
|
{
|
|
await Utils.TencentSMS.Pull(Context, Context.Students.Find(Student.Id), true);
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostRankAsync()
|
|
{
|
|
var s = Context.Students.Find(Student.Id);
|
|
s.Score = score;
|
|
s.Status = status.已评分;
|
|
Context.SaveChanges();
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> OnPostResultAsync()
|
|
{
|
|
var stu = Context.Students.Find(Student.Id);
|
|
if (stu.Status == status.通过)
|
|
await Utils.TencentSMS.Send(Context, SMSType.Accept, stu, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
|
else if (stu.Status == status.不通过)
|
|
await Utils.TencentSMS.Send(Context, SMSType.Reject, stu, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostSignAsync()
|
|
{
|
|
var stu = Context.Students.Find(Student.Id);
|
|
await Utils.TencentSMS.Send(Context, SMSType.Signed, stu, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostSelectTimeAsync()
|
|
{
|
|
var stu = Context.Students.Find(Student.Id);
|
|
await Utils.TencentSMS.Send(Context, SMSType.TimeSelect, stu, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
|
stu.Status = status.需调整时间;
|
|
Context.SaveChanges();
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostTimeAsync()
|
|
{
|
|
var stu = Context.Students.Find(Student.Id);
|
|
await Utils.TencentSMS.Send(Context, SMSType.TimeSet, stu, Context.Users.Find(int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
|
|
stu.Status = status.已确认时间;
|
|
Context.SaveChanges();
|
|
return Construct(Student.Id.ToString());
|
|
}
|
|
}
|
|
}
|