Beispiel #1
0
        public async Task <IActionResult> GetById(int peerGradeId)
        {
            GetPeerGradeByIdDto dto = new GetPeerGradeByIdDto {
                Id = peerGradeId
            };
            ServiceResponse <PeerGradeInfoDto> response = await _peerGradeService.GetPeerGradeById(dto);

            if (response.Success)
            {
                return(Ok(response));
            }
            return(NotFound(response));
        }
Beispiel #2
0
        public async Task <ServiceResponse <PeerGradeInfoDto> > GetPeerGradeById(GetPeerGradeByIdDto getPeerGradeDto)
        {
            ServiceResponse <PeerGradeInfoDto> response = new ServiceResponse <PeerGradeInfoDto>();
            User user = await _context.Users
                        .Include(u => u.InstructedCourses)
                        .FirstOrDefaultAsync(u => u.Id == GetUserId());

            PeerGrade peerGrade = await _context.PeerGrades.FirstOrDefaultAsync(pg => pg.Id == getPeerGradeDto.Id);

            if (peerGrade == null)
            {
                response.Data    = null;
                response.Message = "There is no peer grade with this id";
                response.Success = false;
                return(response);
            }

            PeerGradeInfoDto dto = new PeerGradeInfoDto
            {
                Id             = peerGrade.Id,
                ProjectGroupId = peerGrade.ProjectGroupId,
                ReviewerId     = peerGrade.ReviewerId,
                RevieweeId     = peerGrade.RevieweeId,
                MaxGrade       = peerGrade.MaxGrade,
                Grade          = peerGrade.Grade,
                Comment        = peerGrade.Comment,
                LastEdited     = peerGrade.LastEdited
            };

            ProjectGroup projectGroup = await _context.ProjectGroups
                                        .FirstOrDefaultAsync(rg => rg.Id == dto.ProjectGroupId);


            if (user == null || (!doesUserInstruct(user, projectGroup.AffiliatedCourseId) && user.Id != dto.ReviewerId))
            {
                response.Data    = null;
                response.Message = "You are not authorized to see this peer grade";
                response.Success = false;
                return(response);
            }

            response.Data    = dto;
            response.Message = "Success";
            response.Success = true;

            return(response);
        }