public IActionResult Index(string providerCode, string courseCode, ResultsFilter filter) { if (featureFlags.RedirectToRailsPageCourse) { return(redirectUrlService.RedirectToNewApp("/course/" + $"{providerCode}" + "/" + $"{courseCode}")); } var course = _api.GetCourse(providerCode, courseCode); var feeCaps = _api.GetFeeCaps(); var latestFeeCaps = feeCaps.OrderByDescending(x => x.EndYear).FirstOrDefault(); if (course == null || latestFeeCaps == null) { return(NotFound()); } var viewModel = new CourseDetailsViewModel() { Course = course, Finance = new Shared.ViewModels.FinanceViewModel(course, latestFeeCaps), PreviewMode = false }; return(View(viewModel)); }
public IActionResult QualificationGet(ResultsFilter model) { // Put the posted qualifications into a comma separated string model.qualifications = model.qualification.Any() ? string.Join(",", model.qualification.Select(q => Enum.GetName(typeof(QualificationOption), q))) : string.Join(",", Enum.GetNames(typeof(QualificationOption))); model.qualification = new List <QualificationOption>(); // Remove this from the url return(View(model)); }
private IActionResult FullTextPost(ResultsFilter filter) { filter = filter.WithoutLocation(); var queryIsEmpty = string.IsNullOrWhiteSpace(filter.query); if (queryIsEmpty) { TempData.Put("Errors", new ErrorViewModel("query", "Training provider", "Please enter the name of a training provider", Url.Action("Location"))); return(RedirectToAction("Location", filter.ToRouteValues())); } var suggestions = _api.GetProviderSuggestions(filter.query); var noSuggestions = suggestions.Count == 0; // Note: this is the same block of code as the above. It's repeated because hoisting the logic for // the _api.GetProviderSuggestions call would make it call needlessly on queries which are empty. if (noSuggestions) { TempData.Put("Errors", new ErrorViewModel("query", "Training provider", "Please enter the name of a training provider", Url.Action("Location"))); return(RedirectToAction("Location", filter.ToRouteValues())); } var queryIsExactMatch = suggestions.Any(x => x.Name.Equals(filter.query, StringComparison.InvariantCultureIgnoreCase)); if (!queryIsExactMatch) { TempData.Put("Suggestions", suggestions); return(RedirectToAction("Provider", filter.ToRouteValues())); } return(RedirectToAction("Index", "Results", filter.ToRouteValues())); }
public IActionResult LocationWizardGet(ResultsFilter filter) { ViewBag.IsInWizard = true; //filter.qualification = filter.qualification.Any() ? filter.qualification : new List<QualificationOption> { QualificationOption.QtsOnly, QualificationOption.PgdePgceWithQts, QualificationOption.Other }; filter.qualifications = !string.IsNullOrWhiteSpace(filter.qualifications) ? filter.qualifications : string.Join(",", Enum.GetNames(typeof(QualificationOption))); return(LocationGet(filter)); }
public IActionResult QualificationPost(ResultsFilter model) { model.page = null; // Put the posted qualifications into a comma separated string model.qualifications = model.qualification.Any() ? string.Join(",", model.qualification.Select(q => Enum.GetName(typeof(QualificationOption), q))) : string.Join(",", Enum.GetNames(typeof(QualificationOption))); model.qualification = new List <QualificationOption>(); // Remove this from the url return(RedirectToAction("Index", "Results", model.ToRouteValues())); }
public async Task <IActionResult> LocationPost(ResultsFilter filter) { filter.page = null; if (filter.LocationOption == LocationOption.Specific) { return(FullTextPost(filter)); } var isInWizard = ViewBag.IsInWizard == true; filter.query = null; if (filter.LocationOption == LocationOption.Unset) { TempData.Put("Errors", new ErrorViewModel("l", "Please choose an option", null, Url.Action("Location"))); return(RedirectToAction(isInWizard ? "LocationWizard" : "Location", filter.WithoutLocation().ToRouteValues())); } if (filter.LocationOption == LocationOption.No) { return(isInWizard ? RedirectToAction("SubjectWizard", filter.WithoutLocation().ToRouteValues()) : RedirectToAction("Index", "Results", filter.WithoutLocation().ToRouteValues())); } if (string.IsNullOrWhiteSpace(filter.lq)) { TempData.Put("Errors", new ErrorViewModel("lq", "Postcode, town or city", "Please enter a postcode, city or town in England", Url.Action("Location"))); return(RedirectToAction(isInWizard ? "LocationWizard" : "Location", filter.ToRouteValues())); } var coords = await ResolveAddressAsync(filter.lq); if (coords == null) { TempData.Put("Errors", new ErrorViewModel("lq", "Postcode, town or city", "We couldn't find this location, please check your input and try again.", Url.Action("Location"))); return(RedirectToAction(isInWizard ? "LocationWizard" : "Location", filter.ToRouteValues())); } else { filter.lat = coords.Latitude; filter.lng = coords.Longitude; filter.loc = coords.FormattedLocation; filter.page = null; filter.sortby = (int)SortByOption.Distance; var cid = Request.Cookies.TryGetValue("_gid", out string gid) ? gid : ""; _gaClient.TrackEvent(cid, "Form: Location", "Selected Granularity", coords.Granularity); _gaClient.TrackEvent(cid, "Form: Location", "Selected Region", coords.Region); } return(isInWizard ? RedirectToAction("SubjectWizard", filter.ToRouteValues()) : RedirectToAction("Index", "Results", filter.ToRouteValues())); }
public IActionResult Vacancy(ResultsFilter model) { if (_featureFlags.RedirectToRailsPageVacancy) { return(_redirectUrlService.RedirectToNewApp()); } return(View(model)); }
public IActionResult StudyType(ResultsFilter model) { if (_featureFlags.RedirectToRailsPageStudyType) { return(_redirectUrlService.RedirectToNewApp()); } return(View(model)); }
public IActionResult SubjectWizardGet(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageSubjectWizard) { return(_redirectUrlService.RedirectToNewApp()); } ViewBag.IsInWizard = true; return(SubjectGet(filter)); }
public IActionResult Funding(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageFunding) { return(_redirectUrlService.RedirectToNewApp()); } ViewBag.Errors = TempData.Get <ErrorViewModel>("Errors") ?? new ErrorViewModel(); return(View("Funding", filter)); }
public IActionResult Provider(ResultsFilter filter) { List <Provider> suggestions = TempData.Get <List <Provider> >("Suggestions"); if (suggestions == null) { suggestions = _api.GetProviderSuggestions(filter.query); } ViewBag.suggestions = suggestions; return(View("Provider", filter)); }
public IActionResult QualificationGet(ResultsFilter model) { if (_featureFlags.RedirectToRailsPageQualification) { return(_redirectUrlService.RedirectToNewApp()); } // Put the posted qualifications into a comma separated string model.qualifications = model.qualification.Any() ? string.Join(",", model.qualification.Select(q => Enum.GetName(typeof(QualificationOption), q))) : string.Join(",", Enum.GetNames(typeof(QualificationOption))); model.qualification = new List <QualificationOption>(); // Remove this from the url return(View(model)); }
public IActionResult LocationWizardGet(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageLocationWizard) { return(_redirectUrlService.RedirectToNewApp()); } ViewBag.IsInWizard = true; //filter.qualification = filter.qualification.Any() ? filter.qualification : new List<QualificationOption> { QualificationOption.QtsOnly, QualificationOption.PgdePgceWithQts, QualificationOption.Other }; filter.qualifications = !string.IsNullOrWhiteSpace(filter.qualifications) ? filter.qualifications : string.Join(",", Enum.GetNames(typeof(QualificationOption))); return(LocationGet(filter)); }
public IActionResult SubjectGet(ResultsFilter filter) { var subjectAreas = _api.GetSubjectAreas(); var viewModel = new SubjectFilterViewModel { SubjectAreas = subjectAreas, FilterModel = filter }; ViewBag.Errors = TempData.Get <ErrorViewModel>("Errors"); return(View("Subject", viewModel)); }
public IActionResult SubjectPost(ResultsFilter filter) { filter.page = null; var isInWizard = ViewBag.IsInWizard == true; if (!filter.SelectedSubjects.Any() && !filter.senCourses) { TempData.Put("Errors", new ErrorViewModel("subjects", "Please choose at least one subject", null, Url.Action("Subject"))); return(RedirectToAction(isInWizard ? "SubjectWizard" : "Subject", filter.ToRouteValues())); } return(RedirectToAction("Index", "Results", filter.ToRouteValues())); }
public IActionResult LocationGet(ResultsFilter filter) { var viewModel = new LocationFilterViewModel { FilterModel = filter }; var errors = TempData.Get <ErrorViewModel>("Errors"); if (errors != null && errors.AppliesToUrl(Url.Action("Location"))) { viewModel.Errors = errors; } return(View("Location", viewModel)); }
public IActionResult ResultsMap(ResultsFilter filter) { var subjects = _api.GetSubjects(); filter.qualifications = !string.IsNullOrWhiteSpace(filter.qualifications) ? filter.qualifications : string.Join(",", Enum.GetNames(typeof(QualificationOption))); FilteredList <Subject> filteredSubjects; if (filter.SelectedSubjects.Count > 0) { filteredSubjects = new FilteredList <Subject>( subjects.Where(subject => filter.SelectedSubjects.Contains(subject.Id)).ToList(), subjects.Count ); } else { filteredSubjects = new FilteredList <Subject>(subjects, subjects.Count); } var mapsEnabled = _featureFlags.Maps; PaginatedList <Course> courses; var queryFilter = filter.ToQueryFilter(); var viewModel = new ResultsViewModel { Subjects = filteredSubjects, FilterModel = filter, MapsEnabled = mapsEnabled }; queryFilter.pageSize = 0; courses = _api.GetCourses(queryFilter); var courseGroups = GroupByProvider(courses); IMapProjection <CourseGroup> mapProjection = new MapProjection <CourseGroup>(courseGroups, filter.Coordinates, 400, filter.zoomlevel); viewModel.Map = new MapViewModel { CourseGroups = mapProjection.Markers, MyLocation = filter.Coordinates, Map = mapProjection, }; viewModel.Courses = courses; return(View(viewModel)); }
public IActionResult Provider(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageProvider) { return(_redirectUrlService.RedirectToNewApp()); } List <Provider> suggestions = TempData.Get <List <Provider> >("Suggestions"); if (suggestions == null) { suggestions = _api.GetProviderSuggestions(filter.query); } ViewBag.suggestions = suggestions; return(View("Provider", filter)); }
public IActionResult Index(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageResults) { return(_redirectUrlService.RedirectToNewApp()); } var subjects = _api.GetSubjects(); if (subjects == null) { throw new Exception("Failed to retrieve subject list from api"); } filter.qualifications = !string.IsNullOrWhiteSpace(filter.qualifications) ? filter.qualifications : string.Join(",", Enum.GetNames(typeof(QualificationOption))); FilteredList <Subject> filteredSubjects; if (filter.SelectedSubjects.Count > 0) { filteredSubjects = new FilteredList <Subject>( subjects.Where(subject => filter.SelectedSubjects.Contains(subject.Id)).ToList(), subjects.Count ); } else { filteredSubjects = new FilteredList <Subject>(subjects, subjects.Count); } var mapsEnabled = _featureFlags.Maps; var queryFilter = filter.ToQueryFilter(); var viewModel = new ResultsViewModel { Subjects = filteredSubjects, FilterModel = filter, MapsEnabled = mapsEnabled }; queryFilter.pageSize = 10; viewModel.Courses = _api.GetCourses(queryFilter); return(View(viewModel)); }
private string GetSiteMapContents() { var emptyQuery = new ResultsFilter().ToQueryFilter(); emptyQuery.pageSize = 10_000_000; var allCourses = _api.GetCourses(emptyQuery).Items; var stringBuilder = new StringBuilder(); foreach (var item in allCourses) { var action = Url.Action("Index", "Course", new { providerCode = item.Provider.ProviderCode, courseCode = item.ProgrammeCode }, Request.Scheme); stringBuilder.AppendLine(action); } return(stringBuilder.ToString()); }
public IActionResult SubjectGet(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageSubject) { return(_redirectUrlService.RedirectToNewApp()); } var subjectAreas = _api.GetSubjectAreas(); var viewModel = new SubjectFilterViewModel { SubjectAreas = subjectAreas, FilterModel = filter }; ViewBag.Errors = TempData.Get <ErrorViewModel>("Errors"); return(View("Subject", viewModel)); }
public void SetUp() { _mockApi = new Mock <ISearchAndCompareApi>(); _mockFlag = new Mock <IFeatureFlags>(); _redirectUrlMock = new Mock <IRedirectUrlService>(); _resultsController = new ResultsController(_mockApi.Object, _mockFlag.Object, _redirectUrlMock.Object) { TempData = new Mock <ITempDataDictionary>().Object }; _resultsFilter = new ResultsFilter { funding = 2, hasvacancies = true, fulltime = true, parttime = false, }; }
public IActionResult LocationGet(ResultsFilter filter) { if (_featureFlags.RedirectToRailsPageLocation) { return(_redirectUrlService.RedirectToNewApp()); } var viewModel = new LocationFilterViewModel { FilterModel = filter }; var errors = TempData.Get <ErrorViewModel>("Errors"); if (errors != null && errors.AppliesToUrl(Url.Action("Location"))) { viewModel.Errors = errors; } return(View("Location", viewModel)); }
public void SetUp() { _mockApi = new Mock <ISearchAndCompareApi>(); _mockFlag = new Mock <IFeatureFlags>(); var mockGeocoder = new Mock <IGeocoder>(); _redirectUrlMock = new Mock <IRedirectUrlService>(); _filterController = new FilterController(_mockApi.Object, mockGeocoder.Object, TelemetryClientHelper.GetMocked(), new GoogleAnalyticsClient(null, null), _redirectUrlMock.Object, _mockFlag.Object) { TempData = new Mock <ITempDataDictionary>().Object }; _resultsFilter = new ResultsFilter { funding = 2, hasvacancies = true, fulltime = true, parttime = false, }; }
public async Task <TResponse> SendAsync <TResponse>(string httpMethod, string absoluteUrl, object request, CancellationToken token = default) { var client = GetHttpClient(); if (!HttpUtils.HasRequestBody(httpMethod) && request != null) { var queryString = QueryStringSerializer.SerializeToString(request); if (!string.IsNullOrEmpty(queryString)) { absoluteUrl += "?" + queryString; } } try { absoluteUrl = new Uri(absoluteUrl).ToString(); } catch (Exception ex) { if (log.IsDebugEnabled) { log.Debug("Could not parse URL: " + absoluteUrl, ex); } } var filterResponse = ResultsFilter?.Invoke(typeof(TResponse), httpMethod, absoluteUrl, request); if (filterResponse is TResponse typedResponse) { return(typedResponse); } var httpReq = CreateRequest(httpMethod, absoluteUrl, request); try { var httpRes = await client.SendAsync(httpReq, token).ConfigAwait(); if (typeof(TResponse) == typeof(HttpResponseMessage)) { return((TResponse)(object)httpRes); } if (httpRes.StatusCode == HttpStatusCode.Unauthorized) { var hasRefreshToken = RefreshToken != null; if (EnableAutoRefreshToken && hasRefreshToken) { var refreshDto = new GetAccessToken { RefreshToken = RefreshToken, }; var uri = this.RefreshTokenUri ?? this.BaseUri.CombineWith(refreshDto.ToPostUrl()); this.BearerToken = null; this.CookieContainer?.DeleteCookie(new Uri(BaseUri), "ss-tok"); try { var accessTokenResponse = await this.PostAsync <GetAccessTokenResponse>(uri, refreshDto, token).ConfigAwait(); var accessToken = accessTokenResponse?.AccessToken; var tokenCookie = this.GetTokenCookie(); var refreshRequest = CreateRequest(httpMethod, absoluteUrl, request); if (!string.IsNullOrEmpty(accessToken)) { refreshRequest.AddBearerToken(this.BearerToken = accessToken); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); } else if (tokenCookie != null) { this.SetTokenCookie(tokenCookie); } else { throw new RefreshTokenException("Could not retrieve new AccessToken from: " + uri); } var refreshTokenResponse = await client.SendAsync(refreshRequest, token).ConfigAwait(); return(await ConvertToResponse <TResponse>(refreshTokenResponse, httpMethod, absoluteUrl, refreshRequest, token).ConfigAwait()); } catch (Exception e) { if (e.UnwrapIfSingleException() is WebServiceException refreshEx) { throw new RefreshTokenException(refreshEx); } throw; } } if (UserName != null && Password != null && client.DefaultRequestHeaders.Authorization == null) { AddBasicAuth(client); httpReq = CreateRequest(httpMethod, absoluteUrl, request); var response = await client.SendAsync(httpReq, token).ConfigAwait(); return(await ConvertToResponse <TResponse>(response, httpMethod, absoluteUrl, request, token).ConfigAwait()); } } return(await ConvertToResponse <TResponse>(httpRes, httpMethod, absoluteUrl, request, token).ConfigAwait()); } catch (Exception e) { log.Error(e, "HttpClient Exception: " + e.Message); throw; } }
public IActionResult SubjectWizardPost(ResultsFilter filter) { ViewBag.IsInWizard = true; return(SubjectPost(filter)); }
/// <summary> /// Constructor which initializes Filter property using input field. /// </summary> /// <param name="list">List of surveys which are used during filtering operation.</param> public ResultsFilterViewModel(ObservableCollection <SurveyBasicInfo> list) { Filter = new ResultsFilter(list); }
/// <summary> /// Default constructor. /// </summary> public ResultsFilterViewModel() { Filter = new ResultsFilter(); ProgressBar = new ProcessingBar(); ResultSender = new SendResult(); }
public Task <TResponse> SendAsync <TResponse>(string httpMethod, string absoluteUrl, object request, CancellationToken token = default(CancellationToken)) { var client = GetHttpClient(); if (!HttpUtils.HasRequestBody(httpMethod) && request != null) { var queryString = QueryStringSerializer.SerializeToString(request); if (!string.IsNullOrEmpty(queryString)) { absoluteUrl += "?" + queryString; } } try { absoluteUrl = new Uri(absoluteUrl).ToString(); } catch (Exception ex) { if (log.IsDebugEnabled) { log.Debug("Could not parse URL: " + absoluteUrl, ex); } } var response = ResultsFilter?.Invoke(typeof(TResponse), httpMethod, absoluteUrl, request); if (response is TResponse) { var tcs = new TaskCompletionSource <TResponse>(); tcs.SetResult((TResponse)response); return(tcs.Task); } if (token == default(CancellationToken)) { if (CancelTokenSource == null) { CancelTokenSource = new CancellationTokenSource(); } token = CancelTokenSource.Token; } var httpReq = CreateRequest(httpMethod, absoluteUrl, request); var sendAsyncTask = client.SendAsync(httpReq, token); if (typeof(TResponse) == typeof(HttpResponseMessage)) { return((Task <TResponse>)(object) sendAsyncTask); } return(sendAsyncTask .ContinueWith(responseTask => { var httpRes = responseTask.Result; if (httpRes.StatusCode == HttpStatusCode.Unauthorized) { if (RefreshToken != null) { var refreshDto = new GetAccessToken { RefreshToken = RefreshToken }; var uri = this.RefreshTokenUri ?? this.BaseUri.CombineWith(refreshDto.ToPostUrl()); return this.PostAsync <GetAccessTokenResponse>(uri, refreshDto) .ContinueWith(t => { if (t.IsFaulted) { if (t.Exception.UnwrapIfSingleException() is WebServiceException refreshEx) { throw new RefreshTokenException(refreshEx); } throw t.Exception; } var accessToken = t.Result?.AccessToken; if (string.IsNullOrEmpty(accessToken)) { throw new RefreshTokenException("Could not retrieve new AccessToken from: " + uri); } var refreshRequest = CreateRequest(httpMethod, absoluteUrl, request); if (this.GetTokenCookie() != null) { this.SetTokenCookie(accessToken); } else { refreshRequest.AddBearerToken(this.BearerToken = accessToken); } return client.SendAsync(refreshRequest, token).ContinueWith(refreshTask => ConvertToResponse <TResponse>(refreshTask.Result, httpMethod, absoluteUrl, refreshRequest, token), token).Unwrap(); }, token).Unwrap(); } if (UserName != null && Password != null && client.DefaultRequestHeaders.Authorization == null) { AddBasicAuth(client); httpReq = CreateRequest(httpMethod, absoluteUrl, request); sendAsyncTask = client.SendAsync(httpReq, token); return sendAsyncTask.ContinueWith(t => ConvertToResponse <TResponse>(t.Result, httpMethod, absoluteUrl, request, token), token).Unwrap(); } } return ConvertToResponse <TResponse>(httpRes, httpMethod, absoluteUrl, request, token); }, token).Unwrap()); }
/// <summary> /// Constructor which initializes Filter property using input field. /// </summary> /// <param name="list">List of surveys which are used during filtering operation.</param> public ResultsFilterViewModel(ObservableCollection<SurveyBasicInfo> list) { Filter = new ResultsFilter(list); }
public IActionResult Map(ResultsFilter filter) { return(RedirectToAction("Index", "Results", filter.ToRouteValues())); }