public MediatorResponse <TraineeshipApplicationViewModel> ReviewSaveAndExit(TraineeshipApplicationViewModel traineeshipApplicationViewModel) { var validationResult = _traineeshipApplicationViewModelServerValidator.Validate(traineeshipApplicationViewModel); if (!validationResult.IsValid) { return(GetMediatorResponse(TraineeshipApplicationMediatorCodes.ReviewSaveAndContinue.FailedValidation, traineeshipApplicationViewModel, validationResult)); } try { _applicationProvider.UpdateTraineeshipApplicationViewModelNotes(traineeshipApplicationViewModel.ApplicationSelection.ApplicationId, traineeshipApplicationViewModel.Notes, true); return(GetMediatorResponse(TraineeshipApplicationMediatorCodes.ReviewSaveAndContinue.Ok, traineeshipApplicationViewModel)); } catch (Exception) { var viewModel = GetFailedUpdateTraineeshipApplicationViewModel(traineeshipApplicationViewModel.ApplicationSelection); return(GetMediatorResponse(TraineeshipApplicationMediatorCodes.ReviewSaveAndContinue.Error, viewModel, ApplicationViewModelMessages.UpdateNotesFailed, UserMessageLevel.Error)); } }
public MediatorResponse <TraineeshipApplicationViewModel> Submit(Guid candidateId, int vacancyId, TraineeshipApplicationViewModel viewModel) { viewModel = StripApplicationViewModelBeforeValidation(viewModel); var savedModel = _traineeshipApplicationProvider.GetApplicationViewModel(candidateId, vacancyId); if (savedModel.HasError()) { return(GetMediatorResponse(TraineeshipApplicationMediatorCodes.Submit.Error, viewModel, ApplicationPageMessages.SubmitApplicationFailed, UserMessageLevel.Warning, new { id = vacancyId })); } var result = _traineeshipApplicationViewModelServer.Validate(viewModel); viewModel = _traineeshipApplicationProvider.PatchApplicationViewModel(candidateId, savedModel, viewModel); if (!result.IsValid) { return(GetMediatorResponse(TraineeshipApplicationMediatorCodes.Submit.ValidationError, viewModel, result)); } var submittedApplicationModel = _traineeshipApplicationProvider.SubmitApplication(candidateId, vacancyId, viewModel); if (submittedApplicationModel.ViewModelStatus == ApplicationViewModelStatus.ApplicationInIncorrectState) { return(GetMediatorResponse <TraineeshipApplicationViewModel>(TraineeshipApplicationMediatorCodes.Submit.IncorrectState)); } if (submittedApplicationModel.ViewModelStatus == ApplicationViewModelStatus.Error) { return(GetMediatorResponse(TraineeshipApplicationMediatorCodes.Submit.Error, viewModel, ApplicationPageMessages.SubmitApplicationFailed, UserMessageLevel.Warning, new { id = vacancyId })); } var parameters = new { id = vacancyId, vacancyReference = submittedApplicationModel.VacancyDetail.VacancyReference, vacancyTitle = submittedApplicationModel.VacancyDetail.Title }; return(GetMediatorResponse <TraineeshipApplicationViewModel>(TraineeshipApplicationMediatorCodes.Submit.Ok, parameters: parameters)); }