Beispiel #1
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");
            }
        }
Beispiel #2
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));
            }
        }
        // GET: Lesson
        public ActionResult Index()
        {
            _db = new XCourseContext();

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

            return(View(lessonList));
        }
Beispiel #4
0
        // GET: Teacher
        public ActionResult Index()
        {
            XCourseContext db = new XCourseContext();

            List <Teacher> model = db.Teachers.ToList();

            return(View(model));
        }
Beispiel #5
0
        public ActionResult Delete(int id)
        {
            XCourseContext db = new XCourseContext();

            Teacher model = db.Teachers.Find(id);

            return(View(model));
        }
        public ActionResult CreatePartial()
        {
            _db = new XCourseContext();

            SelectList teachersList = new SelectList(_db.Teachers.ToList(), "Id", "FullName");

            ViewData["TeachersList"] = teachersList;

            return(PartialView("Create_Content"));
        }
Beispiel #7
0
        public ActionResult Create()
        {
            db = new XCourseContext();

            List <Teacher> allTeachers = db.Teachers.ToList();

            SelectList teachersSelectList = new SelectList(allTeachers, "Id", "FullName");

            ViewBag.Teachers = teachersSelectList;

            return(View());
        }
Beispiel #8
0
        // GET: Student
        public ActionResult Index()
        {
            db = new XCourseContext();

            List <Student> model = db.Students.ToList();


            //string resultMessage = (string)TempData["ResultMessage"];
            //TempData.Keep("ResultMessage");

            //resultMessage = (string)TempData.Peek("ResultMessage");

            return(View(model));
        }
Beispiel #9
0
        public ActionResult Edit(int id)
        {
            XCourseContext db = new XCourseContext();

            Teacher model = db.Teachers.Find(id);

            if (model == null)
            {
                return(HttpNotFound());
                //return View("Error");
                //return RedirectToAction("Index");
            }

            return(View(model));
        }
Beispiel #10
0
        public ActionResult Login(Credential credential)
        {
            _db = new XCourseContext();

            Models.User user = _db.Users.FirstOrDefault(u => u.Username == credential.Username && u.Password == credential.Password);

            if (user == null)
            {
                TempData["ResultMessage"] = "Kullanıcı adınız veya şifreniz hatalı! Tekrar deneyin.";
                return(View());
            }
            else
            {
                Session["User"] = user;
                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #11
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));
            }
        }
Beispiel #12
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"));
            }
        }