Esempio n. 1
0
        //
        // GET: /Course/Create
        public ActionResult Create()
        {
            var subjects = _repo.Subjects.All;
            var faculties = _repo.Faculties.All;
            var course = new Course();

            var vm = new CourseInputModel(course, subjects, faculties);
            return View(vm);
        }
Esempio n. 2
0
        public ActionResult Create(Course course)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    _repo.Courses.Add(course);
                    _repo.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Esempio n. 3
0
        public ActionResult Edit(int id, Course course)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var item = _repo.Courses.All.FirstOrDefault(c => c.Id == id);
                    item.Name = course.Name;
                    item.Code = course.Code;
                    item.Start = course.Start;
                    item.Credit = course.Credit;
                    item.FacultyId = course.FacultyId;
                    item.SubjectId = course.SubjectId;
                    _repo.SaveChanges();

                    return RedirectToAction("Index");
                }
                var subjects = _repo.Subjects.All;
                var faculties = _repo.Faculties.All;
                var vm = new CourseInputModel(course, subjects, faculties);
                return View(vm);
            }
            catch
            {
                return View();
            }
        }
Esempio n. 4
0
 public CourseInputModel(Course course, IEnumerable subjects, IEnumerable faculties)
 {
     Course = course;
     Subjects = new SelectList(subjects, "Id", "Name", course.SubjectId);
     Faculties = new SelectList(faculties, "Id", "Name", course.FacultyId);
 }