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 CreateStudent(StudentCreateStudentVM model, int? id)
        {
            Student student = new Student();
            Course course = new Course();
            UnitOfWork unitOfWork = new UnitOfWork();
            UserRepository<Student> sRepo = new UserRepository<Student>();
            CourseRepository courseRepo = new CourseRepository();

            if (!ModelState.IsValid)
            {
                List<SelectListItem> list = new List<SelectListItem>();
                if (id != null)
                {
                    var courses = courseRepo.GetAll(filter: c => c.ID == id.Value).FirstOrDefault();
                    list.Add(new SelectListItem() { Text = courses.Name + " || " + courses.FKNumber, Value = courses.ID.ToString() });
                }
                else
                {
                    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);
            }

            int courseID = Convert.ToInt32(model.selectedValueID);
            course = courseRepo.GetAll(filter: c => c.ID == courseID).FirstOrDefault();

            var fkNumberCount = (from t in sRepo.GetAll(filter: x => x.FacultiNumber.Contains(course.FKNumber)).OrderByDescending(s => s.FacultiNumber)
                                 select t).FirstOrDefault();

            student.FirstName = model.FirstName;
            student.LastName = model.LastName;

            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.Active = true;
            Passphrase hash = PasswordHasher.Hash("password");
            student.Hash = hash.Hash;
            student.Salt = hash.Salt;

            student.Username = "******" + student.FacultiNumber;

            sRepo.Save(student);
            if (id != null)
            {
                return RedirectToAction("CreateStudent", "Student", new { id = id });
            }
            return RedirectToAction("ListStudents", "Student");
        }