public ActionResult Create(Teacher model) { XCourseContext db = new XCourseContext(); Teacher teacher = new Teacher(); teacher.FirstName = model.FirstName; teacher.LastName = model.LastName; teacher.Proficiency = model.Proficiency; try { db.Entry(teacher).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); return(RedirectToAction("Index")); //List<Teacher> teacherList = db.Teachers.ToList(); //return View("Index", teacherList); } catch (Exception) { return(View(model)); //return RedirectToAction("Create"); } }
public ActionResult Create(Student model) { Student student = new Student(); student.FirstName = model.FirstName; student.LastName = model.LastName; student.DateOfBirth = model.DateOfBirth; student.TeacherId = model.TeacherId; db = new XCourseContext(); try { db.Entry(student).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); TempData["ResultMessage"] = "Kayıt işlemi başarılı"; TempData["StudentEntity"] = student; return(RedirectToAction("Index")); } catch (Exception ex) { return(View(model)); } }
public ActionResult DeleteConfirmed(int id) { XCourseContext db = new XCourseContext(); Teacher teacher = db.Teachers.Find(id); try { db.Entry(teacher).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { return(View(teacher)); } }