Ejemplo n.º 1
0
        public async Task <ActionResult> FinishedEditing(FinishEditingViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var response = await _employerCommitmentsOrchestrator.GetFinishEditingViewModel(viewModel.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"), viewModel.HashedCommitmentId);

                response.Data = viewModel;

                return(View(response));
            }

            if (viewModel.SaveStatus.IsSend())
            {
                return(RedirectToAction("SubmitExistingCommitment",
                                        new { viewModel.HashedAccountId, viewModel.HashedCommitmentId, viewModel.SaveStatus }));
            }

            if (viewModel.SaveStatus.IsFinalApproval())
            {
                var userDisplayName = OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName);
                var userEmail       = OwinWrapper.GetClaimValue(DasClaimTypes.Email);
                var userId          = OwinWrapper.GetClaimValue(@"sub");
                await _employerCommitmentsOrchestrator.ApproveCommitment(viewModel.HashedAccountId, userId, userDisplayName, userEmail, viewModel.HashedCommitmentId, viewModel.SaveStatus);

                return(RedirectToAction("Approved",
                                        new { viewModel.HashedAccountId, viewModel.HashedCommitmentId }));
            }

            var flashmessage = new FlashMessageViewModel
            {
                Headline = "Details saved but not sent",
                Severity = FlashMessageSeverityLevel.Info
            };

            AddFlashMessageToCookie(flashmessage);

            return(RedirectToAction("YourCohorts", new { hashedAccountId = viewModel.HashedAccountId }));
        }
        public async Task <ActionResult> StatusChangeConfirmation(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusType changeType, WhenToMakeChangeOptions whenToMakeChange, DateTime?dateOfChange, bool?madeRedundant)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _orchestrator.GetChangeStatusConfirmationViewModel(hashedAccountId, hashedApprenticeshipId, changeType, whenToMakeChange, dateOfChange, madeRedundant, OwinWrapper.GetClaimValue(@"sub"));

            return(View(response));
        }
        public async Task <ActionResult> Edit(string hashedAccountId, string hashedApprenticeshipId)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var model = await _orchestrator.GetApprenticeshipForEdit(hashedAccountId, hashedApprenticeshipId, OwinWrapper.GetClaimValue(@"sub"));

            var flashMessage = GetFlashMessageViewModelFromCookie();

            if (flashMessage?.ErrorMessages != null && flashMessage.ErrorMessages.Any())
            {
                model.FlashMessage = flashMessage;
                model.Data.Apprenticeship.ErrorDictionary = flashMessage.ErrorMessages;
            }

            return(View(model));
        }
        public async Task <ActionResult> ChangeStatus(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusViewModel model)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            if (!ModelState.IsValid)
            {
                var response = await _orchestrator.GetChangeStatusChoiceNavigation(hashedAccountId, hashedApprenticeshipId, OwinWrapper.GetClaimValue(@"sub"));

                return(View(response));
            }

            if (model.ChangeType == ChangeStatusType.None)
            {
                return(Redirect(_linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details")));
            }

            return(RedirectToRoute("WhenToApplyChange", new { changeType = model.ChangeType.ToString().ToLower() }));
        }
        public async Task <ActionResult> WhenToApplyChange(string hashedAccountId, string hashedApprenticeshipId, [CustomizeValidator(RuleSet = "default,Date")] ChangeStatusViewModel model)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            if (!ModelState.IsValid)
            {
                var viewResponse = await _orchestrator.GetChangeStatusDateOfChangeViewModel(hashedAccountId, hashedApprenticeshipId, model.ChangeType.Value, OwinWrapper.GetClaimValue(@"sub"));

                return(View(new OrchestratorResponse <WhenToMakeChangeViewModel>()
                {
                    Data = viewResponse.Data
                }));
            }

            var response = await _orchestrator.ValidateWhenToApplyChange(hashedAccountId, hashedApprenticeshipId, model);

            if (!response.ValidationResult.IsValid())
            {
                response.ValidationResult.AddToModelState(ModelState);

                var viewResponse = await _orchestrator.GetChangeStatusDateOfChangeViewModel(hashedAccountId, hashedApprenticeshipId, model.ChangeType.Value, OwinWrapper.GetClaimValue(@"sub"));

                return(View(new OrchestratorResponse <WhenToMakeChangeViewModel>()
                {
                    Data = viewResponse.Data
                }));
            }

            return(RedirectToRoute("MadeRedundant", new { whenToMakeChange = model.WhenToMakeChange, dateOfChange = response.DateOfChange }));
        }
        public async Task <ActionResult> ViewTeam(string hashedAccountId)
        {
            var response = await _employerTeamOrchestrator.GetTeamMembers(hashedAccountId, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            var flashMessage = GetFlashMessageViewModelFromCookie();

            if (flashMessage != null)
            {
                response.FlashMessage = flashMessage;
            }

            return(View(response));
        }
        public async Task <ActionResult> AddOrganisation(string hashedAccountId)
        {
            var response = await _orchestrator.GetAddLegalEntityViewModel(hashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

            return(View(response));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> DeleteApprenticeshipConfirmation(DeleteApprenticeshipConfirmationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var errorResponse = await _employerCommitmentsOrchestrator.GetDeleteApprenticeshipViewModel(viewModel.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"), viewModel.HashedCommitmentId, viewModel.HashedApprenticeshipId);

                return(View(errorResponse));
            }

            if (viewModel.DeleteConfirmed.HasValue && viewModel.DeleteConfirmed.Value)
            {
                await _employerCommitmentsOrchestrator.DeleteApprenticeship(viewModel, OwinWrapper.GetClaimValue(@"sub"), OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName), OwinWrapper.GetClaimValue(DasClaimTypes.Email));

                var flashMessage = new FlashMessageViewModel {
                    Severity = FlashMessageSeverityLevel.Okay, Message = string.Format($"Apprentice record for {viewModel.ApprenticeshipName} deleted")
                };
                AddFlashMessageToCookie(flashMessage);

                return(RedirectToAction("Details", new { viewModel.HashedAccountId, viewModel.HashedCommitmentId }));
            }

            return(RedirectToAction("EditApprenticeship", new { viewModel.HashedAccountId, viewModel.HashedCommitmentId, viewModel.HashedApprenticeshipId }));
        }
Ejemplo n.º 9
0
        private async Task <ActionResult> RedisplayEditApprenticeshipView(ApprenticeshipViewModel apprenticeship)
        {
            var response = await _employerCommitmentsOrchestrator.GetSkeletonApprenticeshipDetails(apprenticeship.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"), apprenticeship.HashedCommitmentId);

            response.Data.Apprenticeship = apprenticeship;

            if (response.Data.Apprenticeship.ErrorDictionary.Any())
            {
                response.FlashMessage = new FlashMessageViewModel
                {
                    Headline      = "Errors to fix",
                    Message       = "Check the following details:",
                    ErrorMessages = apprenticeship.ErrorDictionary,
                    Severity      = FlashMessageSeverityLevel.Error
                };
            }

            return(View("EditApprenticeshipEntry", response));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> AcknowledgementExisting(string hashedAccountId, string hashedCommitmentId, SaveStatus saveStatus)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _employerCommitmentsOrchestrator
                           .GetAcknowledgementModelForExistingCommitment(hashedAccountId, hashedCommitmentId, OwinWrapper.GetClaimValue(@"sub"));

            var status = GetSessionRequestStatus();
            var returnToCohortsList =
                status != RequestStatus.None &&
                await _employerCommitmentsOrchestrator.AnyCohortsForCurrentStatus(hashedAccountId, status);

            var returnUrl = GetReturnUrl(status, hashedAccountId);

            response.Data.BackLink = string.IsNullOrEmpty(returnUrl) || !returnToCohortsList
                ? new LinkViewModel {
                Url = Url.Action("YourCohorts", new { hashedAccountId }), Text = "Return to Your cohorts"
            }
                : new LinkViewModel {
                Url = returnUrl, Text = "Go back to view cohorts"
            };

            response.Data.Content = GetAcknowledgementContent(saveStatus);



            return(View("Acknowledgement", response));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> DeleteApprenticeshipConfirmation(string hashedAccountId, string hashedCommitmentId, string hashedApprenticeshipId)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _employerCommitmentsOrchestrator.GetDeleteApprenticeshipViewModel(hashedAccountId, OwinWrapper.GetClaimValue(@"sub"), hashedCommitmentId, hashedApprenticeshipId);

            return(View(response));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> AcknowledgementNew(string hashedAccountId, string hashedCommitmentId)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _employerCommitmentsOrchestrator
                           .GetAcknowledgementModelForExistingCommitment(hashedAccountId, hashedCommitmentId, OwinWrapper.GetClaimValue(@"sub"));

            response.Data.Content = GetAcknowledgementContent(SaveStatus.Save);

            return(View("Acknowledgement", response));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> SubmitExistingCommitment(string hashedAccountId, string hashedCommitmentId, SaveStatus saveStatus)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _employerCommitmentsOrchestrator.GetSubmitCommitmentModel(hashedAccountId, OwinWrapper.GetClaimValue(@"sub"), hashedCommitmentId, saveStatus);

            return(View("SubmitCommitmentEntry", response));
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> YourCohorts(string hashedAccountId)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var model = await _employerCommitmentsOrchestrator.GetYourCohorts(hashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

            SetFlashMessageOnModel(model);
            return(View(model));
        }
        public async Task <ActionResult> ChangeRole(string hashedAccountId, string email, Role role)
        {
            var response = await _employerTeamOrchestrator.ChangeRole(hashedAccountId, email, role, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            if (response.Status == HttpStatusCode.OK)
            {
                return(View(ControllerConstants.ViewTeamViewName, response));
            }

            var teamMemberResponse = await _employerTeamOrchestrator.GetTeamMemberWhetherActiveOrNot(hashedAccountId, email, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            //We have to override flash message as the change role view has different model to view team view
            teamMemberResponse.FlashMessage = response.FlashMessage;
            teamMemberResponse.Exception    = response.Exception;

            return(View(teamMemberResponse));
        }
Ejemplo n.º 16
0
 private async Task <bool> IsUserRoleAuthorized(string hashedAccountId, params Role[] roles)
 {
     return(await _employerCommitmentsOrchestrator.AuthorizeRole(hashedAccountId, OwinWrapper.GetClaimValue(@"sub"), roles));
 }
        public async Task <ActionResult> Review(string hashedAccountId, string email)
        {
            var invitation = await _employerTeamOrchestrator.GetTeamMemberWhetherActiveOrNot(hashedAccountId, email, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            return(View(invitation));
        }
Ejemplo n.º 18
0
        public async Task <ActionResult> ReadyForApproval(string hashedAccountId)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var model = await _employerCommitmentsOrchestrator.GetAllReadyForApproval(hashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

            SetFlashMessageOnModel(model);
            Session[LastCohortPageSessionKey] = RequestStatus.ReadyForApproval;
            return(View("RequestList", model));
        }
        public async Task <ActionResult> Invite(string hashedAccountId)
        {
            var response = await _employerTeamOrchestrator.GetNewInvitation(hashedAccountId, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            return(View(response));
        }
        public async Task <ActionResult> LevyDeclarationDetail(string hashedAccountId, DateTime fromDate, DateTime toDate)
        {
            var viewModel = await _accountTransactionsOrchestrator.FindAccountLevyDeclarationTransactions(hashedAccountId, fromDate, toDate, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            return(View(ControllerConstants.LevyDeclarationDetailViewName, viewModel));
        }
        public async Task <ActionResult> AddOrganisation(AddLegalEntityViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var orgTypeErrorResponse = new OrchestratorResponse <AddLegalEntityViewModel>
                {
                    Data = model
                };

                orgTypeErrorResponse.Data.AddErrorsFromModelState(ModelState);

                orgTypeErrorResponse.Status       = HttpStatusCode.BadRequest;
                orgTypeErrorResponse.FlashMessage = new FlashMessageViewModel
                {
                    Severity      = FlashMessageSeverityLevel.Error,
                    ErrorMessages = orgTypeErrorResponse.Data.ErrorDictionary,
                    Headline      = "Errors to fix",
                    Message       = "Check the following details:"
                };
                return(View(orgTypeErrorResponse));
            }

            OrchestratorResponse <OrganisationDetailsViewModel> response;

            //TODO this can be removed once we determine which is slow in prod
            var stopwatch = new System.Diagnostics.Stopwatch();

            try
            {
                stopwatch.Start();

                switch (model.OrganisationType)
                {
                case OrganisationType.Charities:
                    response = await FindCharity(model.CharityRegistrationNumber, model.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

                    break;

                case OrganisationType.CompaniesHouse:
                    response = await FindCompany(model.CompaniesHouseNumber, model.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

                    break;

                case OrganisationType.PublicBodies:
                    var searchResponse = await FindPublicSectorOrganisation(model.PublicBodyName, model.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

                    if (searchResponse.Status == HttpStatusCode.OK)
                    {
                        if (searchResponse.Data.Results.Data.Count != 1 ||
                            searchResponse.Data.Results.Data.All(x => x.AddedToAccount))
                        {
                            return(View("ViewPublicSectorOrganisationSearchResults", searchResponse));
                        }

                        response = new OrchestratorResponse <OrganisationDetailsViewModel>
                        {
                            Data   = searchResponse.Data.Results.Data.FirstOrDefault(),
                            Status = searchResponse.Status
                        };
                    }
                    else
                    {
                        response = new OrchestratorResponse <OrganisationDetailsViewModel>
                        {
                            Data   = new OrganisationDetailsViewModel(),
                            Status = searchResponse.Status
                        };
                        response.Data.ErrorDictionary = searchResponse.Data.ErrorDictionary;
                    }

                    break;

                case OrganisationType.Other:
                    return(RedirectToAction("AddOtherOrganisationDetails", "Organisation", new { model.HashedAccountId }));

                default:
                    throw new NotImplementedException("Org Type Not Implemented");
                }
            }
            finally
            {
                stopwatch.Stop();
                _logger.Info($"Company Search for {model.OrganisationType} took {stopwatch.ElapsedMilliseconds / 1000d}s");
            }

            if (response.Status == HttpStatusCode.OK)
            {
                //Removes empty address entries (i.e. ' , , ')
                var address = (response.Data?.Address ?? string.Empty).Replace(",", string.Empty);

                if (string.IsNullOrWhiteSpace(address))
                {
                    var addressViewModel = _mapper.Map <FindOrganisationAddressViewModel>(response.Data);

                    var addressResponse = new OrchestratorResponse <FindOrganisationAddressViewModel>
                    {
                        Data = addressViewModel
                    };

                    return(View("FindAddress", addressResponse));
                }

                return(View("ConfirmOrganisationDetails", response));
            }

            var errorResponse = new OrchestratorResponse <AddLegalEntityViewModel>
            {
                Data   = model,
                Status = HttpStatusCode.OK
            };

            errorResponse.Data.ErrorDictionary = response.Data.ErrorDictionary;

            errorResponse.FlashMessage = new FlashMessageViewModel
            {
                Severity      = FlashMessageSeverityLevel.Error,
                ErrorMessages = errorResponse.Data.ErrorDictionary,
                Headline      = "Errors to fix",
                Message       = "Check the following details:"
            };

            return(View("AddOrganisation", errorResponse));
        }
        public async Task <ActionResult> ProviderPaymentSummary(string hashedAccountId, long ukprn, DateTime fromDate, DateTime toDate)
        {
            var viewModel = await _accountTransactionsOrchestrator.GetProviderPaymentSummary(hashedAccountId, ukprn, fromDate, toDate, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            return(View(ControllerConstants.ProviderPaymentSummaryViewName, viewModel));
        }
        public async Task <ActionResult> WhenToApplyChange(string hashedAccountId, string hashedApprenticeshipId, ChangeStatusType changeType)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await _orchestrator.GetChangeStatusDateOfChangeViewModel(hashedAccountId, hashedApprenticeshipId, changeType, OwinWrapper.GetClaimValue(@"sub"));

            if (response.Data.SkipToMadeRedundantQuestion)
            {
                return(RedirectToRoute("MadeRedundant", new
                {
                    changeType = response.Data.ChangeStatusViewModel.ChangeType.ToString().ToLower(),
                    whenToMakeChange = WhenToMakeChangeOptions.Immediately,
                    dateOfChange = default(DateTime?)
                }));
            }

            if (response.Data.SkipToConfirmationPage)
            {
                return(RedirectToRoute("StatusChangeConfirmation", new
                {
                    changeType = response.Data.ChangeStatusViewModel.ChangeType.ToString().ToLower(),
                    whenToMakeChange = WhenToMakeChangeOptions.Immediately,
                    dateOfChange = default(DateTime?)
                }));
            }

            return(View(new OrchestratorResponse <WhenToMakeChangeViewModel>
            {
                Data = response.Data
            }));
        }
        public async Task <ActionResult> Cancel(string invitationId, string email, string hashedAccountId, int cancel)
        {
            if (cancel != 1)
            {
                return(RedirectToAction(ControllerConstants.ViewTeamViewName, new { HashedAccountId = hashedAccountId }));
            }

            var response = await _employerTeamOrchestrator.Cancel(email, hashedAccountId, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

            return(View(ControllerConstants.ViewTeamViewName, response));
        }
        public async Task <ActionResult> HasApprenticeBeenMadeRedundant(string hashedAccountId, string hashedApprenticeshipId, [CustomizeValidator(RuleSet = "default,Date,Redundant")] ChangeStatusViewModel model)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            if (!ModelState.IsValid)
            {
                var viewResponse = await _orchestrator.GetRedundantViewModel(hashedAccountId, hashedApprenticeshipId, model.ChangeType.Value,
                                                                             model.DateOfChange.DateTime, model.WhenToMakeChange, OwinWrapper.GetClaimValue(@"sub"), model.MadeRedundant);

                return(View(new OrchestratorResponse <RedundantApprenticeViewModel>
                {
                    Data = viewResponse.Data
                }));
            }

            return(RedirectToRoute("StatusChangeConfirmation", new
            {
                changeType = model.ChangeType,
                whenToMakeChange = model.WhenToMakeChange,
                dateOfChange = model.DateOfChange.DateTime,
                madeRedundant = model.MadeRedundant
            }));
        }
        public async Task <ActionResult> Resend(string hashedAccountId, string email, string name)
        {
            var response = await _employerTeamOrchestrator.Resend(email, hashedAccountId, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName), name);

            return(View(ControllerConstants.ViewTeamViewName, response));
        }
        public async Task <ActionResult> StatusChangeConfirmation(string hashedAccountId, string hashedApprenticeshipId, [CustomizeValidator(RuleSet = "default,Date,Confirm")] ChangeStatusViewModel model)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            if (!ModelState.IsValid)
            {
                var response = await _orchestrator.GetChangeStatusConfirmationViewModel(hashedAccountId, hashedApprenticeshipId, model.ChangeType.Value, model.WhenToMakeChange, model.DateOfChange.DateTime, model.MadeRedundant, OwinWrapper.GetClaimValue(@"sub"));

                return(View(response));
            }

            if (model.ChangeConfirmed.HasValue && !model.ChangeConfirmed.Value)
            {
                return(Redirect(_linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details")));
            }


            await _orchestrator.UpdateStatus(hashedAccountId, hashedApprenticeshipId, model, OwinWrapper.GetClaimValue(@"sub"), OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName),
                                             OwinWrapper.GetClaimValue(DasClaimTypes.Email));

            var flashmessage = new FlashMessageViewModel
            {
                Message  = GetStatusMessage(model.ChangeType),
                Severity = FlashMessageSeverityLevel.Okay
            };

            AddFlashMessageToCookie(flashmessage);

            return(Redirect(_linkGenerator.CommitmentsV2Link($"{hashedAccountId}/apprentices/{hashedApprenticeshipId}/details")));
        }
        public async Task <ActionResult> Remove(long userId, string hashedAccountId, string email, int remove)
        {
            Exception      exception;
            HttpStatusCode httpStatusCode;

            try
            {
                if (remove != 1)
                {
                    return(RedirectToAction(ControllerConstants.ViewTeamViewName, new { HashedAccountId = hashedAccountId }));
                }

                var response = await _employerTeamOrchestrator.Remove(userId, hashedAccountId, OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName));

                return(View(ControllerConstants.ViewTeamViewName, response));
            }
            catch (InvalidRequestException e)
            {
                httpStatusCode = HttpStatusCode.BadRequest;
                exception      = e;
            }
            catch (UnauthorizedAccessException e)
            {
                httpStatusCode = HttpStatusCode.Unauthorized;
                exception      = e;
            }

            var errorResponse = await _employerTeamOrchestrator.Review(hashedAccountId, email);

            errorResponse.Status    = httpStatusCode;
            errorResponse.Exception = exception;

            return(View(errorResponse));
        }
        public async Task <ActionResult> ConfirmChanges(ApprenticeshipViewModel apprenticeship)
        {
            if (!await IsUserRoleAuthorized(apprenticeship.HashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            if (!ModelState.IsValid)
            {
                apprenticeship.AddErrorsFromModelState(ModelState);
            }

            var model = await _orchestrator.GetConfirmChangesModel(
                apprenticeship.HashedAccountId,
                apprenticeship.HashedApprenticeshipId,
                OwinWrapper.GetClaimValue(@"sub"),
                apprenticeship);

            var validatorResult = await _orchestrator.ValidateApprenticeship(apprenticeship, model.Data);

            if (validatorResult.Any())
            {
                apprenticeship.AddErrorsFromDictionary(validatorResult);
            }

            if (apprenticeship.ErrorDictionary.Any())
            {
                var viewModel = await _orchestrator.GetApprenticeshipForEdit(apprenticeship.HashedAccountId, apprenticeship.HashedApprenticeshipId, OwinWrapper.GetClaimValue(@"sub"));

                viewModel.Data.Apprenticeship = apprenticeship;
                SetErrorMessage(viewModel, viewModel.Data.Apprenticeship.ErrorDictionary);

                return(View("Edit", viewModel));
            }

            if (!AnyChanges(model.Data))
            {
                var viewModel = await _orchestrator.GetApprenticeshipForEdit(apprenticeship.HashedAccountId, apprenticeship.HashedApprenticeshipId, OwinWrapper.GetClaimValue(@"sub"));

                viewModel.Data.Apprenticeship = apprenticeship;
                viewModel.Data.Apprenticeship.ErrorDictionary.Add("NoChangesRequested", "No changes made");

                SetErrorMessage(viewModel, viewModel.Data.Apprenticeship.ErrorDictionary);

                return(View("Edit", viewModel));
            }

            _orchestrator.CreateApprenticeshipViewModelCookie(model.Data);

            return(RedirectToAction("ConfirmChanges"));
        }
Ejemplo n.º 30
0
        public async Task <ActionResult> EditApprenticeship(ApprenticeshipViewModel apprenticeship)
        {
            if (!ModelState.IsValid)
            {
                apprenticeship.AddErrorsFromModelState(ModelState);
            }

            var validatorResult = await _employerCommitmentsOrchestrator.ValidateApprenticeship(apprenticeship);

            if (validatorResult.Any())
            {
                apprenticeship.AddErrorsFromDictionary(validatorResult);
            }

            if (apprenticeship.ErrorDictionary.Any())
            {
                return(await RedisplayEditApprenticeshipView(apprenticeship));
            }

            try
            {
                await _employerCommitmentsOrchestrator.UpdateApprenticeship(apprenticeship, OwinWrapper.GetClaimValue(@"sub"));
            }
            catch (InvalidRequestException ex)
            {
                apprenticeship.AddErrorsFromDictionary(ex.ErrorMessages);
                return(await RedisplayEditApprenticeshipView(apprenticeship));
            }

            return(RedirectToAction("Details", new { hashedAccountId = apprenticeship.HashedAccountId, hashedCommitmentId = apprenticeship.HashedCommitmentId }));
        }