public async Task <IActionResult> DownloadByGroup(int projectGroupId, int gradingUserId) { GetProjectGradeDto dto = new GetProjectGradeDto { GradedProjectGroupID = projectGroupId, GradingUserId = gradingUserId }; ServiceResponse <string> response = await _projectGradeService.DownloadProjectGradeByGroupAndUser(dto); if (response.Success) { string path = response.Data; string type = GetContentType(path); if (type == null) { return(BadRequest("this file type is not supported")); } var memory = new MemoryStream(); using (var stream = new FileStream(path, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; return(File(memory, type, Path.GetFileName(path))); } return(NotFound(response)); }
public async Task <IActionResult> GetByUsersAndGroup(int gradedProjectGroupId, int gradingUserId) { GetProjectGradeDto dto = new GetProjectGradeDto { GradedProjectGroupID = gradedProjectGroupId, GradingUserId = gradingUserId }; ServiceResponse <ProjectGradeInfoDto> response = await _projectGradeService.GetProjectGradeByUserAndGroup(dto); if (response.Success) { return(Ok(response)); } return(NotFound(response)); }
public async Task <ServiceResponse <string> > DownloadProjectGradeByGroupAndUser(GetProjectGradeDto dto) { ServiceResponse <string> response = new ServiceResponse <string>(); User user = await _context.Users .Include(u => u.InstructedCourses) .FirstOrDefaultAsync(u => u.Id == GetUserId()); ProjectGroup projectGroup = await _context.ProjectGroups .Include(pg => pg.GroupMembers) .FirstOrDefaultAsync(rg => rg.Id == dto.GradedProjectGroupID); User grader = await _context.Users .Include(u => u.InstructedCourses) .FirstOrDefaultAsync(u => u.Id == dto.GradingUserId); if (projectGroup == null) { response.Data = null; response.Message = "There is no project group with this id"; response.Success = false; return(response); } ProjectGrade projectGrade = await _context.ProjectGrades.Include(pg => pg.GradingUser) .FirstOrDefaultAsync(pg => pg.GradingUserId == dto.GradingUserId && pg.GradedProjectGroupID == dto.GradedProjectGroupID); if (projectGrade == null) { response.Data = null; response.Message = "There is no such project grade"; response.Success = false; return(response); } if (!projectGrade.HasFile) { response.Data = null; response.Message = "There is no file in this grade"; response.Success = false; return(response); } response.Data = projectGrade.FilePath; response.Message = "Success"; response.Success = true; return(response); }
public async Task <ServiceResponse <ProjectGradeInfoDto> > GetProjectGradeByUserAndGroup(GetProjectGradeDto getProjectGradeDto) { ServiceResponse <ProjectGradeInfoDto> response = new ServiceResponse <ProjectGradeInfoDto>(); User user = await _context.Users .Include(u => u.InstructedCourses) .FirstOrDefaultAsync(u => u.Id == GetUserId()); ProjectGroup projectGroup = await _context.ProjectGroups .Include(pg => pg.GroupMembers) .FirstOrDefaultAsync(rg => rg.Id == getProjectGradeDto.GradedProjectGroupID); User grader = await _context.Users .Include(u => u.InstructedCourses) .FirstOrDefaultAsync(u => u.Id == getProjectGradeDto.GradingUserId); if (projectGroup == null) { response.Data = null; response.Message = "There is no project group with this id"; response.Success = false; return(response); } ProjectGrade projectGrade = await _context.ProjectGrades.Include(pg => pg.GradingUser) .FirstOrDefaultAsync(pg => pg.GradingUserId == getProjectGradeDto.GradingUserId && pg.GradedProjectGroupID == getProjectGradeDto.GradedProjectGroupID); if (projectGrade == null) { response.Data = null; response.Message = "There is no such project grade"; response.Success = false; return(response); } ProjectGradeInfoDto dto = new ProjectGradeInfoDto { Id = projectGrade.Id, MaxGrade = projectGrade.MaxGrade, Grade = projectGrade.Grade, Comment = projectGrade.Description, LastEdited = projectGrade.LastEdited, userInProjectGradeDto = new UserInProjectGradeDto { Id = projectGrade.GradingUser.Id, email = projectGrade.GradingUser.Email, name = projectGrade.GradingUser.Name }, GradingUserId = user.Id, projectGroupInProjectGradeDto = new ProjectGroupInProjectGradeDto { Id = user.Id, AffiliatedSectionId = projectGrade.GradedProjectGroup.AffiliatedSectionId, AffiliatedCourseId = projectGrade.GradedProjectGroup.AffiliatedCourseId, ConfirmationState = projectGrade.GradedProjectGroup.ConfirmationState, ConfirmedUserNumber = projectGrade.GradedProjectGroup.ConfirmedUserNumber, ProjectInformation = projectGrade.GradedProjectGroup.ProjectInformation, ConfirmedGroupMembers = projectGrade.GradedProjectGroup.ConfirmedGroupMembers }, GradedProjectGroupID = projectGrade.GradedProjectGroup.Id, FileEndpoint = string.Format("ProjectGrade/DownloadById/{0}", projectGrade.Id), HasFile = projectGrade.HasFile }; response.Data = dto; response.Message = "Success"; response.Success = true; return(response); }