Exemplo n.º 1
0
        /// <summary>
        /// Gets data of class mapped to classid.
        /// </summary>
        /// <param name="classid">ID of class to get data of</param>
        /// <returns>ViewClassVM with data of class mapped to classid</returns>
        public ViewClassVM GetClass(int classid)
        {
            ViewClassVM ClassToView = new ViewClassVM();

            //LINQ Query to pull Class data
            var viewClass = (from classes in _context.Classes
                             join teachers in _context.Teachers on classes.TeacherId equals teachers.TeacherId
                             select new
            {
                classes.ClassId,
                classes.TeacherId,
                teachers.TeacherFirstName,
                teachers.TeacherLastName,
                teachers.Email,
                classes.ClassName,
                classes.Period,
                classes.Location
            })
                            .Where(s => s.ClassId == classid).FirstOrDefault();

            //Insert LINQ values into ViewClassVM
            ClassToView.ClassId          = viewClass.ClassId;
            ClassToView.TeacherId        = viewClass.TeacherId;
            ClassToView.TeacherFirstName = viewClass.TeacherFirstName;
            ClassToView.TeacherLastName  = viewClass.TeacherLastName;
            ClassToView.Email            = viewClass.Email;
            ClassToView.ClassName        = viewClass.ClassName;
            ClassToView.Period           = viewClass.Period;
            ClassToView.Location         = viewClass.Location;

            return(ClassToView);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Admin page with data of class tied to classid.
        /// Data includes: Class Name, Teacher information, Class Period and Location, enrolled students
        /// </summary>
        /// <param name="classid">ClassID of class to view</param>
        /// <returns>View: ViewClass?classid</returns>
        public async Task <IActionResult> ViewClass(int classid)
        {
            ViewClassVM classToView = _adminRepository.GetClass(classid);

            classToView.EnrolledStudents = _teacherRepository.GetEnrolledStudents(classid);
            classToView.StudentAverages  = _teacherRepository.GetStudentAverages(classid);
            classToView.AllTeachers      = _adminRepository.GetAllTeachers();

            return(await Task.Run(() => View(classToView)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Teacher page to view data of class mapped to classid
        /// </summary>
        /// <param name="classid">ID of class to view</param>
        /// <returns>View: ViewClass?classid</returns>
        public async Task <IActionResult> ViewClass(int classid)
        {
            //Verification to ensure that teacher is tied to class
            int teacherid = _teacherRepository.GetTeacherIdFromEmail(this.User.Identity.Name);

            if (!_teacherRepository.IsTeacherForClass(teacherid, classid))
            {
                return(RedirectToAction(nameof(Classes)));
            }

            ViewClassVM classToView = _adminRepository.GetClass(classid);

            classToView.EnrolledStudents = _teacherRepository.GetEnrolledStudents(classid);
            classToView.StudentAverages  = _teacherRepository.GetStudentAverages(classid);

            return(await Task.Run(() => View(classToView)));
        }