64 lines
1.7 KiB
C#
64 lines
1.7 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 DeleteModel : PageModel
|
|
{
|
|
private readonly _2021_backend.Data.BackendContext Context;
|
|
|
|
public DeleteModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
[BindProperty]
|
|
public Submission Submission { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(string? strid)
|
|
{
|
|
Guid id = Guid.Parse(strid);
|
|
if (id == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
Submission = Context.Submissions.FirstOrDefault(m => m.Guid == id);
|
|
|
|
if (Submission == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(Guid? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
Submission = Context.Submissions.Find(id);
|
|
|
|
if (Submission != null)
|
|
{
|
|
var stu = Context.Students.Find(Submission.Host);
|
|
if (stu != null)
|
|
{
|
|
stu.Submissions.Remove(Submission.Guid);
|
|
}
|
|
Context.Submissions.Remove(Submission);
|
|
Context.SaveChanges();
|
|
}
|
|
|
|
return RedirectToPage("./Index");
|
|
}
|
|
}
|
|
}
|