Пример #1
0
        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));
            }
        }
Пример #2
0
        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");
            }
        }
Пример #3
0
        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));
            }
        }
Пример #4
0
        public ActionResult Edit(Teacher model)
        {
            XCourseContext db = new XCourseContext();

            Teacher teacher = db.Teachers.Find(model.Id);

            teacher.FirstName   = model.FirstName;
            teacher.LastName    = model.LastName;
            teacher.Proficiency = model.Proficiency;

            try
            {
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                return(View(model));
            }


            //db.Entry(model);
            //db.Teachers.Attach(model);

            //// Bu aşamada model'in state'i UNCHANGED

            //db.Entry(model).State = System.Data.Entity.EntityState.Modified;

            //// Bu aşamada model'in state'i MODIFIED

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (Exception)
            //{

            //    throw;
            //}
        }
        public ActionResult CreatePartial(Lesson model)
        {
            _db = new XCourseContext();
            Lesson lesson = new Lesson();

            lesson.Name      = model.Name;
            lesson.TeacherId = model.TeacherId;

            _db.Lessons.Add(lesson);

            try
            {
                _db.SaveChanges();

                List <Lesson> lessonList = _db.Lessons.Include("Teacher").ToList();

                return(PartialView("Index_Content", lessonList));
            }
            catch (Exception)
            {
                return(PartialView("Create_Content"));
            }
        }