Exemplo n.º 1
0
        public IActionResult AssignStudents(int id)
        {
            var allStudents = this.context.Student.ToList();
            var course      = this.context.Course.SingleOrDefault(c => c.Id == id);
            CourseStudentAssignment model = new CourseStudentAssignment();

            model.Id          = id;
            model.EndDate     = course.EndDate;
            model.Name        = course.Name;
            model.StartDate   = course.StartDate;
            model.PassCredits = course.PassCredits;
            model.Students    = new List <StudentViewModel>();
            var assignments = new List <StudentCourse>();

            assignments = context.StudentCourse.Where(c => c.CourseId == id).ToList();

            foreach (var student in allStudents)
            {
                bool isAssigned = assignments.Where(p => p.StudentId == student.Id).Any(s => s.Student != null);

                model.Students.Add(new StudentViewModel()
                {
                    StudentId = student.Id, StudentFullName = student.Name, IsAssigned = isAssigned
                });
            }



            return(this.View(model));
        }
Exemplo n.º 2
0
        public IActionResult Details(int id)
        {
            ViewData["action"] = nameof(this.Details);

            var allStudents = this.context.Student.AsNoTracking().ToList();
            var course      = this.context.Course.SingleOrDefault(c => c.Id == id);
            CourseStudentAssignment model = new CourseStudentAssignment();

            model.Id          = id;
            model.EndDate     = course.EndDate;
            model.Name        = course.Name;
            model.StartDate   = course.StartDate;
            model.PassCredits = course.PassCredits;
            model.Students    = new List <StudentViewModel>();
            var assignments = new List <StudentCourse>();

            assignments = context.StudentCourse.Where(c => c.CourseId == id).ToList();

            foreach (var student in allStudents)
            {
                bool isAssigned = assignments.Any(p => p.StudentId == student.Id);

                if (isAssigned)
                {
                    model.Students.Add(new StudentViewModel()
                    {
                        StudentId = student.Id, StudentFullName = student.Name, IsAssigned = isAssigned
                    });
                }
            }
            return(this.View(model));
        }
Exemplo n.º 3
0
        public IActionResult AssignStudents(CourseStudentAssignment assignmentViewModel)
        {
            this.SetStudentsToCourse(assignmentViewModel.Id, assignmentViewModel.Students.Where(p => p.IsAssigned).Select(student => student.StudentId));

            context.StudentCourse.RemoveRange();
            context.SaveChanges();

            return(RedirectToAction("Courses"));
        }