public ActionResult Enroll(int id)
        {
            EnrollStudentViewModel enrollStudent = new EnrollStudentViewModel();

            enrollStudent.Student  = _studentStorage.Students.Find(id);
            enrollStudent.Subjects = _subjectStorage.GetAllBut(enrollStudent.Student.Subjects);
            return(View(enrollStudent));
        }
        public ActionResult Enroll(EnrollStudentViewModel enrollStudent)
        {
            Student student = _studentStorage.Students.Find(enrollStudent.Student.StudentId);
            Subject subject = _subjectStorage.Subjects.Find(enrollStudent.SelectedValue);

            student.Subjects.Add(subject);
            _studentStorage.SaveChanges();
            enrollStudent.SelectedSubject = subject;
            enrollStudent.Student         = student;
            return(View("EnrollDetails", enrollStudent));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Enroll(EnrollStudentViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var userId = int.Parse(this.userManager.GetUserId(HttpContext.User));
                if (userId != model.UserId)
                {
                    return(BadRequest());
                }
                await this.courseService.EnrollStudentToCourseAsync(model.UserId, model.ChosenCourse);

                return(RedirectToAction("Index", "Dashboard"));
            }
            return(View());
        }
Exemplo n.º 4
0
        public ActionResult Enroll(int classId)
        {
            var @class = _dataAccess.ClassManager.GetById(classId);

            if (@class == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            EnrollStudentViewModel viewModel = new EnrollStudentViewModel
            {
                Class         = @class,
                StudentsFound = null
            };

            return(View(viewModel));
        }
Exemplo n.º 5
0
        public IActionResult EnrollStudent(EnrollStudentViewModel enrollStudentViewModel)
        {
            var lecture = _lectureQuery.GetLecture(enrollStudentViewModel.LectureId);

            if (lecture == null)
            {
                throw new ArgumentException(); // või peaks olema NotFound ikka ?
            }

            var command   = new EnrollStudentCommand(enrollStudentViewModel.LectureId, enrollStudentViewModel.StudentName);
            var isSuccess = _messages.Dispatch(command);

            if (isSuccess == false)
            {
                // võiks veateade olla, kas commandist võiks juba Result tulla näiteks
            }
            return(RedirectToAction(nameof(Details), new { Id = enrollStudentViewModel.LectureId }));
        }
        public ActionResult EnrollStudent(string id)
        {
            var db = new ApplicationDbContext();
            //create a list of all users
            List <UsersViewModel> users = AccountController.GetEssentialUserData();
            //Create a list of program enrollments
            List <ProgramEnrollment> allEnrollments = db.ProgramEnrollment.ToList();
            //Create a lookup list for return
            List <EnrollStudentViewModel> returnList = new List <EnrollStudentViewModel>();
            //find all student IDs that are already enrolled in the current program
            List <string> enrolledIDs = new List <String>();

            foreach (var v in allEnrollments)
            {
                //Only look at IDs that match the program ID
                if (v.Program_ID == id)
                {
                    enrolledIDs.Add(v.AccountID); //Add the already registed account Id to the exclusion list
                }
            } //By now you have a list of all ID's that are already registered

            //Parse through all the users to build the model for the view
            foreach (var v in users)
            {
                //check if user is not in the list of enrollments
                if (!enrolledIDs.Contains(v.Id))
                {
                    //Build a program enrollment model
                    EnrollStudentViewModel emodel = new EnrollStudentViewModel();
                    emodel.Program_ID = id;
                    emodel.UserModel  = v;
                    returnList.Add(emodel);
                }
            }
            if (returnList.Count != 0) //If returnlist is not empty
            {
                return(View(returnList));
            }
            else
            {
                return(RedirectToAction("Index", "Program"));
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Enroll()
        {
            var userId          = int.Parse(this.userManager.GetUserId(HttpContext.User));
            var allCourses      = (await this.courseService.GetAllCoursesAsync()).ToList();
            var enrolledCourses = await this.courseService.RetrieveCoursesByStudentAsync(userId);

            foreach (var course in enrolledCourses)
            {
                allCourses.Remove(course);
            }

            var viewModel = new EnrollStudentViewModel()
            {
                UserId           = userId,
                AvailableCourses = new List <SelectListItem>()
            };

            foreach (var course in allCourses)
            {
                viewModel.AvailableCourses.Add(new SelectListItem(course.Name, course.CourseId.ToString()));
            }

            return(View(viewModel));
        }
Exemplo n.º 8
0
        public ActionResult Search(int classId, string searchTerm)
        {
            var @class = _dataAccess.ClassManager.GetById(classId);

            if (@class == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var found    = _dataAccess.UserManager.SearchStudent(searchTerm);
            var enrolled = _dataAccess.ClassManager.GetEnrolledStudents(classId);

            // Set of student ids (for enrolled students)
            HashSet <int> enrolledSet = new HashSet <int>();

            foreach (var student in enrolled)
            {
                enrolledSet.Add(student.Id);
            }

            EnrollStudentViewModel viewModel = new EnrollStudentViewModel
            {
                Class = @class
            };

            foreach (Student student in found)
            {
                viewModel.StudentsFound.Add(new StudentFound
                {
                    Student  = student,
                    Enrolled = enrolledSet.Contains(student.Id)
                });
            }

            return(View("Enroll", viewModel));
        }