// 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(string[] selectedCursuri) { var newStudent = new Student(); if (selectedCursuri != null) { newStudent.StudentCursuri = new List <StudentCurs>(); foreach (var cat in selectedCursuri) { var catToAdd = new StudentCurs { CursID = int.Parse(cat) }; newStudent.StudentCursuri.Add(catToAdd); } } if (await TryUpdateModelAsync <Student>( newStudent, "Student", i => i.Nume, i => i.Prenume, i => i.DataInrolare, i => i.DepartamentID)) { _context.Student.Add(newStudent); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCursData(_context, newStudent); 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() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Departament).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartamentExists(Departament.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// 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(int?id, string[] selectedCursuri) { if (id == null) { return(NotFound()); } var studentToUpdate = await _context.Student .Include(i => i.Departament) .Include(i => i.StudentCursuri) .ThenInclude(i => i.Curs) .FirstOrDefaultAsync(s => s.ID == id); if (studentToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Student>( studentToUpdate, "Student", i => i.Nume, i => i.Prenume, i => i.DataInrolare, i => i.Departament)) { UpdateStudentCursuri(_context, selectedCursuri, studentToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care //este editata UpdateStudentCursuri(_context, selectedCursuri, studentToUpdate); PopulateAssignedCursData(_context, studentToUpdate); 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() { if (!ModelState.IsValid) { return(Page()); } _context.Departament.Add(Departament); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Student = await _context.Student.FindAsync(id); if (Student != null) { _context.Student.Remove(Student); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }