public async Task <IActionResult> GetById(int id, int?groupId = null) { Assignment assignment = await _assignmentService.GetByIdAsync(id, x => x.Subject, x => x.Attachments); if (assignment == null) { return(NotFound()); } if (assignment.Subject.TeacherId != _userService.UserId) { return(Forbid()); } var result = _mapper.Map <AssignmentDetailsDto>(assignment); if (groupId != null) { GroupAssignment ga = _assignmentService.GetGroupAssignment(groupId.Value, id); if (ga != null) { _mapper.Map(ga, assignment); } } return(Ok(result)); }
public async Task <IActionResult> AttachAssignment([FromRoute] int id, [FromBody] int assignmentId) { Lesson lesson = await _lessonService.GetByIdAsync(id); if (lesson == null) { return(NotFound()); } if (lesson.Subject.TeacherId != _userService.UserId) { return(Forbid()); } Assignment assignment = await _assignmentService.GetByIdAsync(assignmentId, x => x.Subject); if (assignment == null) { return(NotFound()); } if (assignment.Subject.TeacherId != _userService.UserId) { return(Forbid()); } lesson.Assignment = assignment; _db.Update(lesson); await _db.SaveChangesAsync(); return(Ok()); }
public async Task GetAssignmentByIdAsync_InvalidId_ReturnsValidation() { // Arrange var service = new AssignmentService(dbContext); int id = -1; // Act var response = await service.GetByIdAsync(id); dbContext.Dispose(); // Assert Assert.Null(response); }
public async Task GetAssignmentByIdAsync_ValidId_ReturnsAssignmentData() { // Arrange var service = new AssignmentService(dbContext); int id = 1; // Act var response = await service.GetByIdAsync(id); dbContext.Dispose(); // Assert Assert.NotNull(response); Assert.True(response.Name.Equals("Set A")); Assert.True(response.Title.Equals("A")); }