예제 #1
0
 public ActionResult EditCourse(Course edit)
 {
     if (ModelState.IsValid)
     {
         if (IsCourseExisted(edit, true))
         {
             //if (CourseCanBeUpdated(edit))
             //{
                 Course course = db.Courses.SingleOrDefault(c => c.courseId == edit.courseId);
                 db.Entry(course).CurrentValues.SetValues(edit);
                 db.SaveChanges();
                 return RedirectToAction("ViewAllCourse");
             //}
             //else
             //    ModelState.AddModelError("Status", "This course has annual course !");
         }
         else
             ModelState.AddModelError("courseName", "This course name have been existed !");
     }
     ViewBag.state = new SelectList(getListStatus(), "Value", "Text", edit.Status);
     ViewBag.roles = new SelectList(db.Faculties, "facultyId", "facultyName", edit.facultyId);
     return View(edit);
 }
예제 #2
0
 public bool IsCourseExisted(Course manipulateCourse, bool edit)
 {
     if (edit == false)//--> Add Course
     {
         var course = db.Courses.SingleOrDefault(c => c.courseName == manipulateCourse.courseName && c.facultyId == manipulateCourse.facultyId);
         if (course == null)//--> there is no course have same name with addCourse(can be Added to DB)
             return true;
     }
     else
     {
         var course = db.Courses.SingleOrDefault(c => c.courseName == manipulateCourse.courseName && c.facultyId == manipulateCourse.facultyId && c.courseId != manipulateCourse.courseId);
         if (course == null)//--> there is no course have same name with addCourse(can be Added to DB)
             return true;
     }
     return false;
 }
예제 #3
0
        public ActionResult AddCourse(Course c)
        {
            if (ModelState.IsValid)
            {
                //c.courseName = c.courseName + " - " + getFacultyNameFromFacultyId(c.facultyId);
                if (IsCourseExisted(c, false))
                {
                    db.sp_InsertCourse(c.courseName, c.facultyId);
                    db.SaveChanges();
                    return RedirectToAction("ViewAllCourse");
                }
                else
                    ModelState.AddModelError("courseName", "This course name have been existed !");
            }

            ViewBag.roles = new SelectList(db.Faculties, "facultyId", "facultyName", c.facultyId);
            return View(c);
        }