public string[] GetStudyModes(ICourseSearchCriteria searchCriteria)
        {
            var results = new string[] { };

            if (searchCriteria.StudyModes != null && searchCriteria.StudyModes.Count > 0)
            {
                results = searchCriteria.StudyModes.ToArray();
            }

            return(results);
        }
        public string GetDfe1619Funded(ICourseSearchCriteria searchCriteria)
        {
            var result = string.Empty;

            if (searchCriteria.IsDfe1619Funded.HasValue)
            {
                result = searchCriteria.IsDfe1619Funded.Value ? "Y" : "N";
            }

            return(result);
        }
        public float GetDistance(ICourseSearchCriteria searchCriteria)
        {
            var result = 0;

            if (searchCriteria.Distance.HasValue && !string.IsNullOrEmpty(searchCriteria.TownOrPostcode))
            {
                result = searchCriteria.Distance.Value;
            }

            return(result);
        }
 public SearchCriteriaStructure CreateSearchCriteriaStructure(ICourseSearchCriteria criteria, string apiKey)
 {
     return(new SearchCriteriaStructure
     {
         APIKey = apiKey,
         SubjectKeyword = criteria.SubjectKeyword.Contains(" ") ? $"'{criteria.SubjectKeyword}'" : criteria.SubjectKeyword,
         QualificationLevels = criteria.QualificationLevels.ToArray(),
         Location = Helper.GetTownOrPostcode(criteria.TownOrPostcode),
         Distance = Helper.GetDistance(criteria),
         DFE1619Funded = Helper.GetDfe1619Funded(criteria),
         StudyModes = Helper.GetStudyModes(criteria),
         DistanceSpecified = Helper.IsDistanceSpecified(criteria),
         AttendanceModes = criteria.AttendanceModes.ToArray(),
         AttendancePatterns = criteria.AttendancePatterns.ToArray()
     });
 }
Пример #5
0
        public async Task <IResult <Common.Models.FindACourse.FindACourseSearchResult> > FindACourseSearch(ICourseSearchCriteria criteria, IPagingOptions options)
        {
            //Bypass current SSL Expiry
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            // Pass the handler to httpclient(from you are calling api)
            //var client = new HttpClient(clientHandler)
            // Call service to get data
            HttpClient client = new HttpClient(clientHandler);

            //var criteria = new { PRN };
            //criteria.SubjectKeyword = "biology";
            criteria.TopResults = Configuration.PerPage;
            criteria.PageNo     = options.PageNo;
            //criteria.QualificationLevels = GetQualLevels(criteria.QualificationLevels):
            //criteria.TownOrPostcode = "b44 9ud";
            criteria.Distance = 100;

            StringContent content = new StringContent(JsonConvert.SerializeObject(criteria), Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Configuration.ApiKey);
            //client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            client.DefaultRequestHeaders.Add("UserName", Configuration.UserName);
            client.DefaultRequestHeaders.Add("Password", Configuration.Password);


            var response = await client.PostAsync($"{Configuration.ApiAddress}/coursesearch", content);

            var jsonResult = await response.Content.ReadAsStringAsync();

            // Return data as model object
            //return Result.Ok(JsonConvert.DeserializeObject<Common.Models.FindACourse.FindACourseSearchResult>(jsonResult));
            return(CreateFindACourseSearchResult(jsonResult, options, Configuration.PerPage));
        }
Пример #6
0
        public IResult <FindACourseSearchResult> CourseDirectorySearch(ICourseSearchCriteria criteria, IPagingOptions options)
        {
            FindACourseService fac = new FindACourseService(FaCConfiguration, CourseAPIConfiguration);

            return(fac.FindACourseSearch(criteria, options).Result);
        }
Пример #7
0
        public async Task <IResult <ICourseSearchResult> > GetYourCoursesByUKPRNAsync(ICourseSearchCriteria criteria)
        {
            Throw.IfNull(criteria, nameof(criteria));
            Throw.IfLessThan(0, criteria.UKPRN.Value, nameof(criteria.UKPRN.Value));
            _logger.LogMethodEnter();

            try
            {
                _logger.LogInformationObject("Get your courses criteria", criteria);
                _logger.LogInformationObject("Get your courses URI", _getYourCoursesUri);

                if (!criteria.UKPRN.HasValue)
                {
                    return(Result.Fail <ICourseSearchResult>("Get your courses unknown UKRLP"));
                }

                var response = await _httpClient.GetAsync(new Uri(_getYourCoursesUri.AbsoluteUri + "&UKPRN=" + criteria.UKPRN));

                _logger.LogHttpResponseMessage("Get your courses service http response", response);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    if (!json.StartsWith("["))
                    {
                        json = "[" + json + "]";
                    }

                    _logger.LogInformationObject("Get your courses service json response", json);
                    IEnumerable <IEnumerable <IEnumerable <Course> > > courses = JsonConvert.DeserializeObject <IEnumerable <IEnumerable <IEnumerable <Course> > > >(json);

                    CourseSearchResult searchResult = new CourseSearchResult(courses);
                    return(Result.Ok <ICourseSearchResult>(searchResult));
                }
                else
                {
                    return(Result.Fail <ICourseSearchResult>("Get your courses service unsuccessful http response"));
                }
            } catch (HttpRequestException hre) {
                _logger.LogException("Get your courses service http request error", hre);
                return(Result.Fail <ICourseSearchResult>("Get your courses service http request error."));
            } catch (Exception e) {
                _logger.LogException("Get your courses service unknown error.", e);
                return(Result.Fail <ICourseSearchResult>("Get your courses service unknown error."));
            } finally {
                _logger.LogMethodExit();
            }
        }
        //public string[] GetAttendanceModes(ICourseSearchCriteria searchCriteria)
        //{
        //    var results = new List<string>();

        //    if (searchCriteria.AttendanceModes != null && searchCriteria.AttendanceModes.Count > 0)
        //    {

        //    }

        //    return results.ToArray();
        //}

        //public string GetAttendanceMode(AttendanceMode attendanceMode)
        //{
        //    switch (attendanceMode)
        //    {
        //        case AttendanceMode.LocationCampus: "AM1"
        //    }
        //}

        public bool IsDistanceSpecified(ICourseSearchCriteria searchCriteria)
        {
            return(searchCriteria.Distance.HasValue && searchCriteria.Distance.Value > 0);
        }