public IActionResult OnPost() { if (ModelState.IsValid) { foreach (var subject in AddSubject) { if (subject.Selected) { Student.Students.Add(new Students { Subject = subjectData.GetSubjectById(Convert.ToInt32(subject.Value)) }); } } studentData.CreateStudent(Student); studentData.Commit(); return(RedirectToPage("./Detail", new { studentId = Student.Id })); } AddSubject = subjectData.GetSubjects().Select(x => new SelectListItem { Selected = false, Value = x.Id.ToString(), Text = x.Name }).ToList(); return(Page()); }
public IActionResult OnPost(int studentId) { var student = studentData.Delete(studentId); studentData.Commit(); if (student == null) { return(RedirectToPage("./NotFound")); } TempData["Message"] = $"{student.Name} deleted"; return(RedirectToPage("./List")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { Skills = htmlHelper.GetEnumSelectList <Skill>(); return(Page()); } if (Student.Id > 0) { studentData.Update(Student); } else { studentData.Add(Student); } studentData.Commit(); return(RedirectToPage("./Detail", new { studentId = Student.Id })); }
public IActionResult OnPost() { if (!ModelState.IsValid) { Quotas = htmlHelper.GetEnumSelectList <Quota>(); Departments = htmlHelper.GetEnumSelectList <Department>(); return(Page()); } if (Student.Id > 0) { studentData.Update(Student); } else { studentData.Add(Student); } studentData.Commit(); TempData["Message"] = "Student saved!"; return(RedirectToPage("./Detail", new { studentId = Student.Id })); }