public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } _instructorRepository.Insert(Instructor); return(RedirectToPage("./Instructor")); }
public ActionResult Create(Instructor instructor, FormCollection fc, string[] selectedCourses) { ViewBag.menu = MENU; if (TryUpdateModel(instructor, "", new string[] { "LastName", "FirstMidName", "HireDate", "OfficeAssignment" })) { repository.Insert(instructor, selectedCourses); repository.Save(); TempData["message"] = string.Format("{0} has been saved", instructor.FullName); return(RedirectToAction("Index")); } PopulateAssignedCourseData(); return(View(instructor)); }
public ActionResult Create(Instructor instructor, string[] selectedCourses) { Dictionary <string, object> res = new Dictionary <string, object>(); try { if (TryUpdateModel(instructor, "", new string[] { "LastName", "FirstMidName", "HireDate", "OfficeAssignment" })) { repository.Insert(instructor, selectedCourses); repository.Save(); res["success"] = 1; res["message"] = string.Format("{0} has been saved", instructor.FullName); } } catch (Exception ex) { res["error"] = 1; res["message"] = ex.ToString(); } return(Json(res, JsonRequestBehavior.AllowGet)); }