internal async Task InitializeAsync() { CourseListRequest courseListRequest = new CourseListRequest() { AccountId = Convert.ToInt32(TYPSY_ACCOUNT_ID), Email = "*****@*****.**", Language = "en", Source = TYPSY_SOURCE, Referrer = this.Referrer }; // Refer to the BaseViewModel to see how the encryption keys are initialized var client = new RestClient(TYPSY_API); var request = new RestRequest("/lms/course-list", Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Typsy-Source", TYPSY_SOURCE); request.AddHeader("Typsy-Timestamp", this.Timestamp); request.AddHeader("Typsy-Account-Id", TYPSY_ACCOUNT_ID); request.AddHeader("Typsy-Key", this.EncryptedKey); request.AddHeader("Referer", this.Referrer); request.AddJsonBody(courseListRequest); var json = await client.ExecuteAsync(request); var response = JsonConvert.DeserializeObject <CourseListResponse>(json.Content); if (response.Success) { this.Courses = response.Courses; } }
public async Task <IActionResult> CourseList([FromBody] CourseListRequest request) { try { CourseList courseList = await courseRepository.CourseList(request); return(Ok(courseList)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
/// <summary> /// Gets a list of courses matching the search criteria in CourseListRequestStructure /// and logs the duration of the search. /// </summary> /// <param name="courseListInput">Search criteria.</param> /// <returns>Populated CourseLisOutput containing matching courses.</returns> public CourseListOutput GetCourseList(CourseListInput courseListInput) { CourseListOutput courseListOutput = new CourseListOutput(new CourseListResponseStructure()); CourseListRequest request = BuildCourseListRequest(courseListInput.CourseListRequest); CourseListResponse response = _courseQuery.GetCourseList(request); courseListOutput.CourseListResponse = BuildCourseListResponseStructure(response, courseListInput.CourseListRequest); // Record search time _courseQuery.RecordSearchTime(Constants.SEARCH_TIME_COLUMN_FLAG, response.SearchHeaderId); return(courseListOutput); }
/// <summary> /// Get matching courses based on request /// </summary> /// <param name="request">search parameters</param> /// <returns>Matching course reponse object</returns> public CourseListResponse GetCourseList(CourseListRequest request) { try { Boolean isPublicAPI = ConfigurationManager.AppSettings["IncludeUCASData"].ToLower() != "true"; Boolean v3SearchEnhancements = ConfigurationManager.AppSettings["UseV3SearchEnhancements"].ToLower() == "true"; Int32 cutoffPercentage; Int32.TryParse(ConfigurationManager.AppSettings["RemoveLowestRankedResultPercentage"], out cutoffPercentage); Boolean providerFreeTextMatch = ConfigurationManager.AppSettings["ProviderFreeTextMatch"].ToLower() == "true"; Boolean courseFreeTextMatch = ConfigurationManager.AppSettings["CourseFreeTextMatch"].ToLower() == "true"; Boolean searchCourseSummary = ConfigurationManager.AppSettings["SearchCourseSummary"].ToLower() == "true"; Boolean searchQualificationTitle = ConfigurationManager.AppSettings["SearchQualificationTitle"].ToLower() == "true"; if (isPublicAPI && String.IsNullOrEmpty(request.APIKey.Trim())) { return(new CourseListResponse()); } Stopwatch stopwatch = Stopwatch.StartNew(); string courseCacheKey = CreateCacheKey(request, v3SearchEnhancements, providerFreeTextMatch, courseFreeTextMatch, searchCourseSummary, searchQualificationTitle); DateTime earlierStartDate; DateTime.TryParse(request.EarliestStartDate, out earlierStartDate); DateTime applyUntil; DateTime.TryParse(request.AppClosedFlag, out applyUntil); CourseListResponse courseResult = CacheHelper.GetCourseListResponse(courseCacheKey); if (courseResult == null) { courseResult = LoadGetCourseList(request, earlierStartDate, applyUntil, isPublicAPI, v3SearchEnhancements, cutoffPercentage, providerFreeTextMatch, courseFreeTextMatch, searchCourseSummary, searchQualificationTitle); CacheHelper.SaveCourseListResponse(courseCacheKey, courseResult); } new DBHelper().LogProviderRequestResponseLog(DBHelper.ServiceMethodName.GetCourseList, stopwatch.ElapsedMilliseconds, DBHelper.Serialize(request), DBHelper.Serialize(courseResult), isPublicAPI, request.APIKey, courseResult.NumberOfRecords); return(courseResult); } catch (Exception ex) { LogException(ex, "GetCourseList"); throw; } }
public async Task <CourseList> CourseList(CourseListRequest request) { int skipRow = (request.Page - 1) * request.PageSize; IQueryable <Course> query = this.RepositoryContext.Courses.AsNoTracking(); if (request.Type.ToLower().Equals("/100off")) { query = query.Where(c => c.Discount_percent == 100); } if (request.Type.ToLower().Equals("/discount")) { query = query.Where(c => c.Discount_percent < 100); } if (!string.IsNullOrEmpty(request.Category)) { query = query.Where(c => c.Category == request.Category); } int totalCount = await query.CountAsync(); List <Course> courses = await query.OrderByDescending(c => c.CreatedDate).Skip(skipRow).Take(request.PageSize) .Select(c => new Course { CourseId = c.CourseId, Title = c.Title, Headline = c.Headline, Image_200_H = c.Image_200_H, RemainingTime = DateTime.Now.Subtract(c.EndTime ?? DateTime.Now), Discount_percent = c.Discount_percent, CreatedDate = c.CreatedDate }).ToListAsync(); CourseList response = new CourseList { TotalCount = totalCount, Courses = courses }; return(response); }
private static string CreateCacheKey(CourseListRequest request, bool v3SearchEnhancements, bool providerFreeTextMatch, bool courseFreeTextMatch, bool searchCourseSummary, bool searchQualificationTitle) { string key = string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}_{13}_{14}_{15}_{16}_{17}_{18}_{19}_{20}_{21}_{22}_{23}_{24}_{25}_{26}_{27}_{28}_{29}_{30}_{31}_{32}_{33}_{34}_{35}", request.A10Codes, request.AdultLRStatus, request.AppClosedFlag, request.AttendanceModes, request.AttendancePatterns, request.Distance, request.DistanceSpecified, request.EarliestStartDate, request.ERAppStatus, request.ERTtgStatus, request.FlexStartFlag, request.IesFlag, request.IlsFlag, request.LdcsCategoryCode, request.Location, request.OtherFundingStatus, request.PageNumber, request.ProviderId, request.ProviderKeyword, request.QualificationLevels, request.QualificationTypes, request.RecordsPerPage, request.SflFlag, request.StudyModes, request.SubjectKeyword, request.TqsFlag, request.TtgFlag, request.ProviderId, request.SortBy, request.DFE1619Funded, request.APIKey, v3SearchEnhancements ? 1 : 0, providerFreeTextMatch ? 1 : 0, courseFreeTextMatch ? 1 : 0, searchCourseSummary ? 1 : 0, searchQualificationTitle ? 1 : 0); return(key); }
private static Response ListCourseResponse(CourseListRequest courseListRequest) { DatabaseManager database = new DatabaseManager(); (MySqlDataReader reader, var Connection) = database.RunQuery($"SELECT course_details.courseid, course_details.coursename, course_details.authorid, account_data.fullname,course_details.rating,course_details.createdon,course_details.videocount " + $"FROM course_details INNER JOIN account_data" + $" WHERE account_data.username = course_details.authorid AND" + $" account_data.username = '******'"); if (reader != null) { CourseListResponse res = new CourseListResponse() { Status = "OK", Reason = "Success" }; res.CourseList = new List <CourseDetails>(); while (reader.Read()) { res.CourseList.Add(new CourseDetails() { CourseID = reader.GetString(0), CourseName = reader.GetString(1), AuthorID = reader.GetString(2), AuthorName = reader.GetString(3), Rating = float.Parse(reader.GetString(4)), CreatedOn = DateTime.Parse(reader.GetString(5)), VideoCount = int.Parse(reader.GetString(6)) }); } Connection.Close(); return(new Response() { Type = ResponseType.CourseList, Content = res, Status = "OK" }); } Connection.Close(); return(new Response() { Content = null, Type = ResponseType.CourseList, Status = "FAIL" }); }
private CourseListResponse LoadGetCourseList(CourseListRequest request, DateTime earlierStartDate, DateTime applyUntil, bool isPublicAPI, bool v3SearchEnhancements, int?cutoffPercentage, bool providerFreeTextMatch, bool courseFreeTextMatch, bool searchCourseSummary, bool searchQualificationTitle) { using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities()) { List <API_CourseList_Get_v2_Result> courseListItems; if (!v3SearchEnhancements) { courseListItems = db.API_CourseList_Get_v2(GetNullableString(request.SubjectKeyword), GetNullableString(request.ProviderKeyword), GetNullableString(request.QualificationTypes), GetNullableString(request.QualificationLevels), GetNullableString(request.StudyModes), GetNullableString(request.AttendanceModes), GetNullableString(request.AttendancePatterns), !earlierStartDate.Equals(DateTime.MinValue) ? earlierStartDate : (DateTime?)null, GetNullableString(request.LdcsCategoryCode), !string.IsNullOrEmpty(request.ERTtgStatus) && request.ERTtgStatus.Equals("Y", StringComparison.CurrentCultureIgnoreCase), GetNullableString(request.A10Codes), !string.IsNullOrEmpty(request.IlsFlag) && request.IlsFlag.Equals("Y", StringComparison.CurrentCultureIgnoreCase), GetNullableString(request.SflFlag), GetNullableString(request.ERTtgStatus), GetNullableString(request.ERAppStatus), GetNullableString(request.AdultLRStatus), GetNullableString(request.OtherFundingStatus), !applyUntil.Equals(DateTime.MinValue) ? applyUntil : (DateTime?)null, !string.IsNullOrEmpty(request.FlexStartFlag) && request.FlexStartFlag.Equals("Y", StringComparison.CurrentCultureIgnoreCase), GetNullableString(request.Location), request.Distance > 0 ? request.Distance : (float?)null, request.PageNumber > 0 ? (int)request.PageNumber : 0, request.RecordsPerPage > 0 ? request.RecordsPerPage : (int?)null, request.SortBy, request.ProviderId > 0 ? request.ProviderId : (Int32?)null, isPublicAPI ? 1 : 0, String.IsNullOrEmpty(request.DFE1619Funded) ? (Boolean?)null : request.DFE1619Funded.Equals("Y", StringComparison.CurrentCultureIgnoreCase), request.APIKey) .ToList(); } else { SearchQuery query = new SearchQuery(GetNullableString(request.SubjectKeyword)); courseListItems = db.API_CourseList_Get_v3(String.Join(" ", query.Include), String.Join(" ", query.Exclude), String.Join("|", query.IncludeExact), String.Join("|", query.ExcludeExact), GetNullableString(request.ProviderKeyword), GetNullableString(request.QualificationTypes), GetNullableString(request.QualificationLevels), GetNullableString(request.StudyModes), GetNullableString(request.AttendanceModes), GetNullableString(request.AttendancePatterns), !earlierStartDate.Equals(DateTime.MinValue) ? earlierStartDate : (DateTime?)null, GetNullableString(request.LdcsCategoryCode), !string.IsNullOrEmpty(request.ERTtgStatus) && request.ERTtgStatus.Equals("Y", StringComparison.CurrentCultureIgnoreCase), GetNullableString(request.A10Codes), !string.IsNullOrEmpty(request.IlsFlag) && request.IlsFlag.Equals("Y", StringComparison.CurrentCultureIgnoreCase), GetNullableString(request.SflFlag), GetNullableString(request.ERTtgStatus), GetNullableString(request.ERAppStatus), GetNullableString(request.AdultLRStatus), GetNullableString(request.OtherFundingStatus), !applyUntil.Equals(DateTime.MinValue) ? applyUntil : (DateTime?)null, !string.IsNullOrEmpty(request.FlexStartFlag) && request.FlexStartFlag.Equals("Y", StringComparison.CurrentCultureIgnoreCase), GetNullableString(request.Location), request.Distance > 0 ? request.Distance : (float?)null, request.PageNumber > 0 ? (int)request.PageNumber : 0, request.RecordsPerPage > 0 ? request.RecordsPerPage : (int?)null, request.SortBy, request.ProviderId > 0 ? request.ProviderId : (Int32?)null, isPublicAPI ? 1 : 0, String.IsNullOrEmpty(request.DFE1619Funded) ? (Boolean?)null : request.DFE1619Funded.Equals("Y", StringComparison.CurrentCultureIgnoreCase), request.APIKey, cutoffPercentage == 0 ? null : cutoffPercentage, providerFreeTextMatch ? 1 : 0, courseFreeTextMatch ? 1 : 0, searchCourseSummary ? 1 : 0, searchQualificationTitle ? 1 : 0) .ToList(); } var response = new CourseListResponse { NumberOfRecords = courseListItems.Count > 0 ? courseListItems.FirstOrDefault().RecordCount.Value : 0, Courses = new List <Course>() }; var categoryCodeList = new DBHelper().LoadCategoryCodes(isPublicAPI ? 1 : 0, request.APIKey); foreach (var courseListItem in courseListItems) { var course = new Course { Provider = new Provider { ProviderName = courseListItem.ProviderName, TFPlusLoans = courseListItem.Loans24Plus, DFE1619Funded = courseListItem.ProviderDfEFunded, FEChoices_LearnerDestination = courseListItem.FEChoices_LearnerDestination, FEChoices_LearnerSatisfaction = courseListItem.FEChoices_LearnerSatisfaction, FEChoices_EmployerSatisfaction = courseListItem.FEChoices_EmployerSatisfaction }, CourseId = courseListItem.CourseId, CourseTitle = courseListItem.CourseTitle, QualificationType = courseListItem.QualificationTypeRef, QualificationLevel = courseListItem.QualificationBulkUploadRef, LdcsCode1 = courseListItem.LDCS1, LdcsCode2 = courseListItem.LDCS2, LdcsCode3 = courseListItem.LDCS3, LdcsCode4 = courseListItem.LDCS4, LdcsCode5 = courseListItem.LDCS5, LdcsDesc1 = GetLdscDescription(courseListItem.LDCS1, categoryCodeList), LdcsDesc2 = GetLdscDescription(courseListItem.LDCS2, categoryCodeList), LdcsDesc3 = GetLdscDescription(courseListItem.LDCS3, categoryCodeList), LdcsDesc4 = GetLdscDescription(courseListItem.LDCS4, categoryCodeList), LdcsDesc5 = GetLdscDescription(courseListItem.LDCS5, categoryCodeList), NumberOfOpportunities = 1, CourseSummary = courseListItem.CourseSummary, Opportunities = new List <Opportunity>() }; Opportunity opportunity = new Opportunity { OpportunityId = courseListItem.CourseInstanceId.ToString(), StudyMode = courseListItem.StudyModeBulkUploadRef, AttendanceMode = courseListItem.AttendanceModeBulkUploadRef, AttendancePattern = courseListItem.AttendancePatternBulkUploadRef, StartDate = courseListItem.StartDate.HasValue ? courseListItem.StartDate.Value.ToString("dd MMMM yyyy") : String.Empty, StartDateDescription = courseListItem.StartDateDescription, EndDate = courseListItem.EndDate.HasValue ? courseListItem.EndDate.Value.ToString("dd MMMM yyyy") : string.Empty, RegionName = courseListItem.RegionName, Distance = courseListItem.Distance.ToString(), DurationUnit = courseListItem.DurationUnitBulkUploadRef, DurationDescription = courseListItem.DurationAsText, DurationValue = courseListItem.DurationUnitId.HasValue ? courseListItem.DurationUnitId.Value : 0, DfE1619Funded = courseListItem.CourseDfEFunded ?? false, Venue = new Venue { VenueName = courseListItem.VenueName, AddressLine1 = courseListItem.AddressLine1, AddressLine2 = courseListItem.AddressLine2, Town = courseListItem.Town, County = courseListItem.County, Postcode = courseListItem.Postcode, Latitude = courseListItem.Latitude.HasValue ? courseListItem.Latitude.Value.ToString() : string.Empty, Longitude = courseListItem.Longitude.HasValue ? courseListItem.Longitude.Value.ToString() : string.Empty }, A10 = new List <String>() }; opportunity.A10.Add(courseListItem.A10FundingCode); course.Opportunities.Add(opportunity); response.Courses.Add(course); } return(response); } }
/// <summary> /// Build CourseListRequest object from CourseListRequstStructure. /// </summary> /// <param name="courseRequest">CourseListRequestStructure data.</param> /// <returns>Populated CourseListRequest object.</returns> private static CourseListRequest BuildCourseListRequest(CourseListRequestStructure courseRequest) { SearchCriteriaStructure searchCriteria = courseRequest.CourseSearchCriteria; CourseListRequest request = new CourseListRequest(); // if seachCriteria not null, populate request. if (searchCriteria != null) { request.APIKey = searchCriteria.APIKey; request.SubjectKeyword = searchCriteria.SubjectKeyword; request.DFE1619Funded = searchCriteria.DFE1619Funded; request.AppClosedFlag = searchCriteria.OppsAppClosedFlag; request.Distance = searchCriteria.Distance; request.DistanceSpecified = searchCriteria.DistanceSpecified; request.EarliestStartDate = searchCriteria.EarliestStartDate; request.FlexStartFlag = searchCriteria.FlexStartFlag; request.IesFlag = searchCriteria.IESFlag; request.IlsFlag = searchCriteria.ILSFlag; if (!string.IsNullOrEmpty(searchCriteria.ProviderID)) { request.ProviderId = Int32.Parse(searchCriteria.ProviderID); } request.ProviderKeyword = searchCriteria.ProviderKeyword; request.SflFlag = searchCriteria.SFLFlag; request.Location = searchCriteria.Location; request.TqsFlag = searchCriteria.TQSFlag; request.TtgFlag = searchCriteria.TTGFlag; // If A10 codes exist, add them to the request. if ((searchCriteria.A10Codes != null) && (searchCriteria.A10Codes.A10Code != null && searchCriteria.A10Codes.A10Code.Length > 0)) { request.A10Codes = Utilities.ConvertToDelimitedString(searchCriteria.A10Codes.A10Code, "|"); } // If Adult LR statuses exist, add them to the request. if (searchCriteria.AdultLRStatus != null && searchCriteria.AdultLRStatus.Length > 0) { request.AdultLRStatus = Utilities.ConvertToDelimitedString(searchCriteria.AdultLRStatus, "|"); } // If Attendance modes exist, add them to the request. if ((searchCriteria.AttendanceModes != null) && (searchCriteria.AttendanceModes.AttendanceMode != null && searchCriteria.AttendanceModes.AttendanceMode.Length > 0)) { request.AttendanceModes = Utilities.ConvertToDelimitedString(searchCriteria.AttendanceModes.AttendanceMode, "|"); } // If Attendance patterns exist, add them to the request. if ((searchCriteria.AttendancePatterns != null) && (searchCriteria.AttendancePatterns.AttendancePattern != null && searchCriteria.AttendancePatterns.AttendancePattern.Length > 0)) { request.AttendancePatterns = Utilities.ConvertToDelimitedString(searchCriteria.AttendancePatterns.AttendancePattern, "|"); } // If ER App statuses exist, add them to the request. if (searchCriteria.ERAppStatus != null && searchCriteria.ERAppStatus.Length > 0) { request.ERAppStatus = Utilities.ConvertToDelimitedString(searchCriteria.ERAppStatus, "|"); } // If ER TTG statuses exist, add them to the request. if (searchCriteria.ERTtgStatus != null && searchCriteria.ERTtgStatus.Length > 0) { request.ERTtgStatus = Utilities.ConvertToDelimitedString(searchCriteria.ERTtgStatus, "|"); } // If LDCS category codes exist, add them to the request. if ((searchCriteria.LDCS != null) && (searchCriteria.LDCS.CategoryCode != null && searchCriteria.LDCS.CategoryCode.Length > 0)) { request.LdcsCategoryCode = Utilities.ConvertToDelimitedString(searchCriteria.LDCS.CategoryCode, "|"); } // If Other funding statuses exist, add them to the request. if (searchCriteria.OtherFundingStatus != null && searchCriteria.OtherFundingStatus.Length > 0) { request.OtherFundingStatus = Utilities.ConvertToDelimitedString(searchCriteria.OtherFundingStatus, "|"); } // If Qualification levels exist, add them to the request. if ((searchCriteria.QualificationLevels != null) && (searchCriteria.QualificationLevels.QualificationLevel != null && searchCriteria.QualificationLevels.QualificationLevel.Length > 0)) { request.QualificationLevels = Utilities.ConvertToDelimitedString(searchCriteria.QualificationLevels.QualificationLevel, "|"); } // If Qualification types exist, add them to the request. if ((searchCriteria.QualificationTypes != null) && (searchCriteria.QualificationTypes.QualificationType != null && searchCriteria.QualificationTypes.QualificationType.Length > 0)) { request.QualificationTypes = Utilities.ConvertToDelimitedString(searchCriteria.QualificationTypes.QualificationType, "|"); } // If Study modes exist, add them to the request. if ((searchCriteria.StudyModes != null) && (searchCriteria.StudyModes.StudyMode != null && searchCriteria.StudyModes.StudyMode.Length > 0)) { request.StudyModes = Utilities.ConvertToDelimitedString(searchCriteria.StudyModes.StudyMode, "|"); } // Add number of records per page to request, default to 20 if does not exist. int recordsPerPage = 0; if (!string.IsNullOrEmpty(courseRequest.RecordsPerPage)) { recordsPerPage = Int32.Parse(courseRequest.RecordsPerPage); } request.RecordsPerPage = (recordsPerPage > 0) ? recordsPerPage : 20; // Add sort by to request. request.SortBy = courseRequest.SortBy.ToString(); // Add page number to request, default to 1 if less than 1. if (!string.IsNullOrEmpty(courseRequest.PageNo)) { long pageNumber = Int64.Parse(courseRequest.PageNo); request.PageNumber = (pageNumber > 0) ? pageNumber : 1; } else { request.PageNumber = 1; } } return(request); }
/// <summary> /// Retrieves courses matching the search criteria in the request. /// </summary> /// <param name="request">Course search criteria.</param> /// <returns>A CourseList Response entity.</returns> public CourseListResponse GetCourseList(CourseListRequest request) { return(_courseGateway.GetCourseList(request)); }