Exemple #1
0
        public async Task <ActionResult> Index(ApprenticeshipSearchViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                ViewBag.SearchReturnUrl = (Request != null && Request.Url != null) ? Request.Url.PathAndQuery : null;

                var candidateId = UserContext == null ? default(Guid?): UserContext.CandidateId;
                var response = _apprenticeshipSearchMediator.SearchValidation(candidateId, model);

                switch (response.Code)
                {
                case ApprenticeshipSearchMediatorCodes.SearchValidation.ValidationError:
                    ModelState.Clear();
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View("Index", response.ViewModel);

                case ApprenticeshipSearchMediatorCodes.SearchValidation.CandidateNotLoggedIn:
                    return RedirectToRoute(CandidateRouteNames.ApprenticeshipSearch);

                case ApprenticeshipSearchMediatorCodes.SearchValidation.Ok:
                    return RedirectToRoute(CandidateRouteNames.ApprenticeshipResults, model.RouteValues);

                case ApprenticeshipSearchMediatorCodes.SearchValidation.RunSavedSearch:
                    {
                        // ReSharper disable once PossibleInvalidOperationException
                        var savedSearchResponse = _apprenticeshipSearchMediator.RunSavedSearch(candidateId.Value, model);

                        switch (savedSearchResponse.Code)
                        {
                        case ApprenticeshipSearchMediatorCodes.SavedSearch.SavedSearchNotFound:
                        case ApprenticeshipSearchMediatorCodes.SavedSearch.RunSaveSearchFailed:
                            SetUserMessage(savedSearchResponse.Message.Text, savedSearchResponse.Message.Level);
                            return RedirectToRoute(CandidateRouteNames.ApprenticeshipSearch);

                        case ApprenticeshipSearchMediatorCodes.SavedSearch.Ok:
                            ModelState.Clear();
                            return Redirect(savedSearchResponse.ViewModel.SearchUrl.Value);
                        }

                        throw new InvalidMediatorCodeException(savedSearchResponse.Code);
                    }
                }

                throw new InvalidMediatorCodeException(response.Code);
            }));
        }
Exemple #2
0
        public async Task <ActionResult> SearchValidation(ApprenticeshipSearchViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                ViewBag.SearchReturnUrl = (Request != null && Request.Url != null) ? Request.Url.PathAndQuery : null;

                var response = _apprenticeshipSearchMediator.SearchValidation(model);

                switch (response.Code)
                {
                case ApprenticeshipSearchMediatorCodes.SearchValidation.ValidationError:
                    ModelState.Clear();
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View("Index", response.ViewModel);

                case ApprenticeshipSearchMediatorCodes.SearchValidation.Ok:
                    return RedirectToAction("Results", model);
                }

                throw new InvalidMediatorCodeException(response.Code);
            }));
        }