public GradeReportVm GetGradesReportForStudent(GetGradeDto getGradesDto)
        {
            var getterUser = _dbContext.Users.FirstOrDefault(x => x.Id == getGradesDto.GetterUserId);

            if (getterUser == null)
            {
                throw new ArgumentNullException("getter user is null");
            }
            if (!_userManager.IsInRoleAsync(getterUser, "Teacher").Result&&
                !_userManager.IsInRoleAsync(getterUser, "Student").Result&&
                !_userManager.IsInRoleAsync(getterUser, "Parent").Result&&
                !_userManager.IsInRoleAsync(getterUser, "Admin").Result)
            {
                throw new InvalidOperationException("The getter user don't have permissions to read.");
            }
            var student = _dbContext.Users.OfType <Student>().FirstOrDefault(x => x.Id == getGradesDto.StudentId);

            if (student == null)
            {
                throw new ArgumentNullException("getter user is null");
            }
            var gradesRaport = Mapper.Map <GradeReportVm>(student);

            return(gradesRaport);
        }
 public void GetGrade(GetGradeDto getGradeDto)
 {
     if (getGradeDto == null)
     {
         throw new Exception("Grade is null");
     }
     //    var getUser = _dbContext.Users.FirstOrDefault(x => x.Id == getGradeDto.GetterUserId);
     //  if (getUser == null)
     //      throw new Exception("User is null");
     //  if (!_userManager.IsInRoleAsync(getUser, "Teacher").Result
     //      && !_userManager.IsInRoleAsync(getUser, "Teacher").Result
     //      && !_userManager.IsInRoleAsync(getUser, "Teacher").Result)
     //  {
     //      throw new InvalidOperationException("You don't have permission");
     //  }
     // // var student = _dbContext.Users.OfType<Student>().FirstOrDefault(s => s.Id == getGradeDto.StudentId);
     ////  if (student == null)
     //      throw new InvalidOperationException("is not a student");
     ///  var gradesReport = Mapper.Map<GradeReportVm>(student);
     return;
 }
示例#3
0
        public IActionResult Details(int studentId)
        {
            var user         = _userManager.GetUserAsync(User).Result;
            var getGradesDto = new GetGradeDto
            {
                StudentId    = user.Id,
                GetterUserId = _userManager.GetUserAsync(User).Result.Id
            };


            if (studentId != 0)
            {
                getGradesDto = new GetGradeDto
                {
                    StudentId    = studentId,
                    GetterUserId = _userManager.GetUserAsync(User).Result.Id
                };
            }
            var studentGradesReport = _gradeService.GetGradesReportForStudent(getGradesDto);

            return(View(studentGradesReport));
        }