Ejemplo n.º 1
0
        public List <StudentCourseGradeViewModel> GetResultByIdGateway(int registrationId)
        {
            string query = "SELECT * FROM StudentCourseGradeViewModel WHERE StdRegId = @StdRegId";

            _command = new SqlCommand(query, _connection);
            _command.Parameters.AddWithValue("@StdRegId", registrationId);
            _connection.Open();

            _reader = _command.ExecuteReader();

            List <StudentCourseGradeViewModel> studentCourseGradeViewModels = new List <StudentCourseGradeViewModel>();

            while (_reader.Read())
            {
                StudentCourseGradeViewModel aStudentCourseGradeViewModel = new StudentCourseGradeViewModel();

                aStudentCourseGradeViewModel.Id         = Convert.ToInt32(_reader["Id"]);
                aStudentCourseGradeViewModel.CourseCode = _reader["CourseCode"].ToString();
                aStudentCourseGradeViewModel.CourseName = _reader["CourseName"].ToString();
                aStudentCourseGradeViewModel.GradeName  = _reader["GradeName"].ToString();

                studentCourseGradeViewModels.Add(aStudentCourseGradeViewModel);
            }

            _reader.Close();

            _connection.Close();


            return(studentCourseGradeViewModels);
        }
        public async Task <IActionResult> Students(int id)
        {
            var courseExists = this.courseService.Exists(id);

            if (!courseExists)
            {
                this.TempData.AddErrorMessage(WebConstants.CourseNotFoundMsg);
                return(this.RedirectToAction(nameof(Courses)));
            }

            var userId = this.userManager.GetUserId(this.User);

            if (userId == null)
            {
                this.TempData.AddErrorMessage(WebConstants.InvalidUserMsg);
                return(this.RedirectToAction(nameof(Courses)));
            }

            var isTrainer = await this.trainerService.IsTrainerForCourseAsync(userId, id);

            if (!isTrainer)
            {
                this.TempData.AddErrorMessage(WebConstants.NotTrainerForCourseMsg);
                return(this.RedirectToAction(nameof(Courses)));
            }

            var model = new StudentCourseGradeViewModel
            {
                Course   = await this.trainerService.CourseByIdAsync(userId, id),
                Students = await this.trainerService.StudentsInCourseAsync(id)
            };

            return(this.View(model));
        }