public ActionResult EditStudent(StudentEditStudentVM model)
        {
            CourseRepository courseRepo = new CourseRepository();

            if (!ModelState.IsValid)
            {
                List<SelectListItem> list = new List<SelectListItem>();
                var courses = courseRepo.GetAll();

                foreach (var item in courses)
                {
                    list.Add(new SelectListItem() { Text = item.Name + " || " + item.FKNumber, Value = item.ID.ToString() });
                }

                model.CoursesList = list;
                return View(model);
            }
            UserRepository<Student> stuRepo = new UserRepository<Student>();
            Student student = new Student();
            Course course = new Course();

            student = stuRepo.GetByID(model.StudentID);

            int courseID = Convert.ToInt32(model.selectedValueID);
            if (model.CourseID != courseID)
            {
                course = courseRepo.GetAll(filter: c => c.ID == courseID).FirstOrDefault();
                var fkNumberCount = (from t in stuRepo.GetAll(filter: x => x.FacultiNumber.Contains(course.FKNumber)).OrderByDescending(s => s.FacultiNumber)
                                     select t).FirstOrDefault();

                if (fkNumberCount == null)
                {
                    student.FacultiNumber = (Convert.ToInt32(course.FKNumber) * 1000 + 1).ToString();
                }
                else
                {
                    student.FacultiNumber = (Convert.ToInt32(fkNumberCount.FacultiNumber) + 1).ToString();
                }
                student.CourseID = courseID;
            }
            student.FirstName = model.FirstName;
            student.Username = "******" + student.FacultiNumber;
            student.LastName = model.LastName;
            student.Active = model.Active;
            stuRepo.Save(student);

            return RedirectToAction("ListStudents", "Student");
        }
        public ActionResult EditStudent(int? id)
        {
            StudentEditStudentVM model = new StudentEditStudentVM();
            UserRepository<Student> stuRepo = new UserRepository<Student>();
            CourseRepository cRepo = new CourseRepository();

            Student student = stuRepo.GetByID(id.Value);

            var courses = cRepo.GetAll();

            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem() { Text = student.Course.Name + " || " + student.Course.FKNumber, Value = student.Course.ID.ToString() });
            foreach (var item in courses)
            {
                if (item.ID != student.Course.ID)
                {
                    list.Add(new SelectListItem() { Text = item.Name + " || " + item.FKNumber, Value = item.ID.ToString() });
                }
            }

            model.StudentID = student.ID;
            model.CourseID = student.CourseID;
            model.FirstName = student.FirstName;
            model.LastName = student.LastName;
            model.Active = student.Active;
            model.CoursesList = list;

            return View(model);
        }