public ActionResult EditCourses(int id, AdminControllerCourseVM courseModel)
 {
     TryUpdateModel(courseModel);
     if (ModelState.IsValid)
     {
         Course course = null;
         CourseRepository coureseRepository = new CourseRepository();
         if (id > 0)
         {
             course = coureseRepository.GetById(id);
             course.Name = courseModel.Name;
             course.Code = courseModel.Code;
             coureseRepository.Save(course);
             return RedirectToAction("ManageCourses");
         }
         else
         {
             course = coureseRepository.GetAll(filter: c => c.Name == courseModel.Name).FirstOrDefault();
             if (course == null)
             {
                 course = new Course();
                 course.Name = courseModel.Name;
                 course.Code = courseModel.Code;
                 coureseRepository.Save(course);
                 return RedirectToAction("ManageCourses");
             }
             else
             {
                 throw new ArgumentException("Invalid course name");
             }
         }
     }
     return View(courseModel);
 }
 public ActionResult ShowCourses()
 {
     AdminControllerCourseVM courseModel = new AdminControllerCourseVM();
     CourseRepository courseRepository = new CourseRepository();
     courseModel.courseList = courseRepository.GetAll();
     return View(courseModel);
 }
        public ActionResult EditCourses(int id)
        {
            Course course = new Course();
            CourseRepository courseRepository = new CourseRepository();
            AdminControllerCourseVM courseModel = new AdminControllerCourseVM();

            if (id > 0)
            {
                course = courseRepository.GetById(id);
                courseModel.Name = course.Name;
                courseModel.Code = course.Code;
                courseModel.CourseID = id;
            }

            if (id == 0)
            {
                courseModel.Code = GenerateCode();
                course.Name = courseModel.Name;
                course.Code = courseModel.Code;
            }
            return View(courseModel);
        }