Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int peerGradeId, int grade, string comment)
        {
            EditPeerGradeDto dto = new EditPeerGradeDto {
                Grade      = grade,
                LastEdited = DateTime.Now,
                Comment    = comment,
                Id         = peerGradeId
            };

            ServiceResponse <PeerGradeInfoDto> response = await _peerGradeService.EditPeerGrade(dto);

            if (response.Success)
            {
                return(Ok(response));
            }
            return(NotFound(response));
        }
Ejemplo n.º 2
0
        public async Task <ServiceResponse <PeerGradeInfoDto> > EditPeerGrade(EditPeerGradeDto editPeerGradeDto)
        {
            ServiceResponse <PeerGradeInfoDto> response = new ServiceResponse <PeerGradeInfoDto>();
            User user = await _context.Users.Include(u => u.ProjectGroups)
                        .ThenInclude(g => g.ProjectGroup)
                        .FirstOrDefaultAsync(u => u.Id == GetUserId());

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


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

            if (peerGrade.ReviewerId != user.Id)
            {
                response.Data    = null;
                response.Message = "You are not authorized to change this peer grade";
                response.Success = false;
                return(response);
            }
            ProjectGroup projectGroup = await _context.ProjectGroups
                                        .Include(g => g.GroupMembers)
                                        .FirstOrDefaultAsync(rg => rg.Id == peerGrade.ProjectGroupId);

            PeerGradeAssignment pga = await _context.PeerGradeAssignments
                                      .FirstOrDefaultAsync(pga => pga.CourseId == projectGroup.AffiliatedCourseId);

            if (pga.DueDate < editPeerGradeDto.LastEdited)
            {
                response.Data    = null;
                response.Message = "Due date has passed for the peer grade assignment";
                response.Success = false;
                return(response);
            }

            if (peerGrade.MaxGrade < editPeerGradeDto.Grade)
            {
                response.Data    = null;
                response.Message = "Grade should be less than or equal to the max grade";
                response.Success = false;
                return(response);
            }

            peerGrade.Grade   = editPeerGradeDto.Grade;
            peerGrade.Comment = editPeerGradeDto.Comment;

            _context.PeerGrades.Update(peerGrade);
            await _context.SaveChangesAsync();



            PeerGradeInfoDto peerGradeInfoDto = 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
            };

            response.Data    = peerGradeInfoDto;
            response.Message = "You successfully entered peer grade";
            response.Success = true;



            return(response);
        }