62 lines
1.8 KiB
C#
62 lines
1.8 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.Threading.Tasks;
|
|
|
|
namespace _2021_backend.Pages.Students
|
|
{
|
|
public class EditModel : PageModel
|
|
{
|
|
public readonly _2021_backend.Data.BackendContext Context;
|
|
|
|
public EditModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
[BindProperty]
|
|
public Student Student { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(string? idstr)
|
|
{
|
|
if (idstr == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
Guid id = Guid.Parse(idstr);
|
|
Student = await Context.Students.AsNoTracking().FirstOrDefaultAsync(m => m.Guid == id);
|
|
|
|
if (Student == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
// To protect from overposting attacks, enable the specific properties you want to bind to.
|
|
// For more details, see https://aka.ms/RazorPagesCRUD.
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
var stu = Context.Students.Find(Student.Guid);
|
|
stu.Status = Student.Status;
|
|
stu.Email = Student.Email;
|
|
stu.Name = Student.Name;
|
|
stu.Stuid = Student.Stuid;
|
|
stu.Tel = Student.Tel;
|
|
stu.Grade = Student.Grade;
|
|
stu.Sex = Student.Sex;
|
|
stu.Yard = Student.Yard;
|
|
Context.SaveChanges();
|
|
return RedirectToPage("./Index");
|
|
}
|
|
|
|
private bool StudentExists(Guid id)
|
|
{
|
|
return Context.Students.Any(e => e.Guid == id);
|
|
}
|
|
}
|
|
}
|