public async Task <ActionResult> CreateApprenticeship(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 RedisplayCreateApprenticeshipView(apprenticeship)); } try { await _employerCommitmentsOrchestrator.CreateApprenticeship(apprenticeship, OwinWrapper.GetClaimValue(@"sub"), OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName), OwinWrapper.GetClaimValue(DasClaimTypes.Email)); } catch (InvalidRequestException ex) { apprenticeship.AddErrorsFromDictionary(ex.ErrorMessages); return(await RedisplayCreateApprenticeshipView(apprenticeship)); } return(RedirectToAction("Details", new { hashedAccountId = apprenticeship.HashedAccountId, hashedCommitmentId = apprenticeship.HashedCommitmentId })); }