public async Task <ActionResult> SubmitChanges(long providerId, string hashedApprenticeshipId, CreateApprenticeshipUpdateViewModel updateApprenticeship)
        {
            var originalApp = await _orchestrator.GetApprenticeship(providerId, hashedApprenticeshipId);

            updateApprenticeship.OriginalApprenticeship = originalApp;

            if (!ModelState.IsValid)
            {
                return(View("ConfirmChanges", updateApprenticeship));
            }

            if (updateApprenticeship.ChangesConfirmed != null && !updateApprenticeship.ChangesConfirmed.Value)
            {
                return(RedirectToAction("Details", new { providerId, hashedApprenticeshipId }));
            }

            await _orchestrator.CreateApprenticeshipUpdate(updateApprenticeship, providerId, CurrentUserId, GetSignedInUser());

            var message = NeedReapproval(updateApprenticeship)
                ? "Suggested changes sent to employer for approval, where needed."
                : "Apprentice updated";

            SetInfoMessage(message, FlashMessageSeverityLevel.Okay);

            return(RedirectToAction("Details", new { providerId, hashedApprenticeshipId }));
        }
예제 #2
0
        public async Task ShouldCallMediatorToCreate()
        {
            var    providerId             = 123;
            string userId                 = "ABC";
            var    expectedApprenticeship = new ApprenticeshipUpdate();
            var    viewModel              = new CreateApprenticeshipUpdateViewModel();
            var    signedInUser           = new SignInUserModel()
            {
                DisplayName = "Bob", Email = "*****@*****.**"
            };

            _mockApprenticeshipMapper.Setup(x => x.MapApprenticeshipUpdate(viewModel)).Returns(expectedApprenticeship);

            await _orchestrator.CreateApprenticeshipUpdate(viewModel, providerId, userId, signedInUser);

            _mockMediator.Verify(
                x =>
                x.Send(
                    It.Is <CreateApprenticeshipUpdateCommand>(
                        c =>
                        c.ProviderId == providerId && c.UserId == userId && c.ApprenticeshipUpdate == expectedApprenticeship && c.UserDisplayName == signedInUser.DisplayName &&
                        c.UserEmailAddress == signedInUser.Email), It.IsAny <CancellationToken>()), Times.Once);
        }