Пример #1
0
        public async Task <ActionResult <AssignmentDto> > UpdateAssignment(UpdateAssignmentDto assignmentDto)
        {
            if (assignmentDto == null)
            {
                return(BadRequest(InvalidAssignmentError));
            }
            if (assignmentDto.Start >= assignmentDto.End)
            {
                return(BadRequest("Start time was on or after end time."));
            }
            var savedAssignment = await AssignmentService.GetAssignment(assignmentDto.Id);

            if (savedAssignment == null)
            {
                return(NotFound());
            }
            if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, savedAssignment.LocationId))
            {
                return(Forbid());
            }

            var updateAssignment  = assignmentDto.Adapt <Assignment>();
            var updatedAssignment = await AssignmentService.UpdateAssignment(updateAssignment);

            return(Ok(updatedAssignment.Adapt <AssignmentDto>()));
        }
Пример #2
0
        public async Task CanRetrieveStructuredAssignment()
        {
            var assignmentId = 1;

            _assignmentRepositoryMock.Setup(x => x.GetAssignment(assignmentId))
            .Returns(Task.FromResult(new Assignment()
            {
                Id = assignmentId, PlanId = 1, UserId = 1, AssignedAt = new System.DateTime(2020, 1, 1, 0, 0, 0)
            }))
            .Verifiable();

            _assignmentRepositoryMock.Setup(x => x.GetAssignment(assignmentId))
            .Returns(Task.FromResult(new Assignment()
            {
                Id = 1, PlanId = 1, UserId = 1
            }))
            .Verifiable();
            _assignmentRepositoryMock.Setup(x => x.GetSignaturesWithUsersForAssignment(assignmentId))
            .Returns(Task.FromResult((new List <SignatureDto>()
            {
                new SignatureDto()
                {
                    Id = 1, SectionLevelId = 1, SectionSkillId = 1
                }
            }).AsEnumerable()))
            .Verifiable();

            var assignment = await _assignmentService.GetAssignment(assignmentId);

            Assert.AreEqual(1, assignment.Signatures.Count());
            _assignmentRepositoryMock.Verify();
        }
Пример #3
0
        public async Task <ActionResult> ExpireAssignment(int id, string expiryReason, DateTimeOffset?expiryDate = null)
        {
            var savedAssignment = await AssignmentService.GetAssignment(id);

            if (savedAssignment == null)
            {
                return(NotFound());
            }
            if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, savedAssignment.LocationId))
            {
                return(Forbid());
            }

            await AssignmentService.ExpireAssignment(id, expiryReason, expiryDate);

            return(NoContent());
        }
Пример #4
0
        public IActionResult AssignmentHome()
        {
            var assignments = _assignmentService.GetAssignment();

            return(View(assignments));
        }