58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using _2021_backend.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace _2021_backend.Pages.Submissions
|
|
{
|
|
public class CreateModel : PageModel
|
|
{
|
|
private readonly _2021_backend.Data.BackendContext Context;
|
|
|
|
public CreateModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
public IActionResult OnGet()
|
|
{
|
|
Submission = new Submission();
|
|
return Page();
|
|
}
|
|
|
|
[BindProperty]
|
|
public Submission Submission { get; set; }
|
|
|
|
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return Page();
|
|
}
|
|
var q = Context.Students.Where(stu => (stu.Name == Submission.Name || stu.Tel == Submission.Tel || stu.Stuid == Submission.Stuid));
|
|
Student stu;
|
|
if (q.Count() == 0)
|
|
{
|
|
stu = Student.create(Submission);
|
|
stu.Status = status.刚报名;
|
|
var q2 = from e in Context.Sessions select e.Guid;
|
|
var lst = q2.ToList();
|
|
stu.Timelist = lst;
|
|
Context.Students.Add(stu);
|
|
}
|
|
else
|
|
{
|
|
stu = q.FirstOrDefault();
|
|
stu.Update(Submission);
|
|
}
|
|
Submission.Host = stu.Guid;
|
|
Context.Submissions.Add(Submission);
|
|
Context.SaveChanges();
|
|
|
|
return RedirectToPage("./Index");
|
|
}
|
|
}
|
|
}
|