/// <summary>
        /// Load course details
        /// </summary>
        /// <param name="courseIds">Course Ids to search</param>
        /// <param name="APIKey"></param>
        /// <returns>List of courses matching the course Ids</returns>
        public List <Course> GetCourseDetails(List <long> courseIds, String APIKey)
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                List <Course> courses     = new List <Course>();
                Boolean       isPublicAPI = ConfigurationManager.AppSettings["IncludeUCASData"].ToLower() != "true";
                if (isPublicAPI && String.IsNullOrEmpty(APIKey.Trim()))
                {
                    return(new List <Course>());
                }

                foreach (int courseId in courseIds)
                {
                    var courseResult = CacheHelper.GetCourseDetailsByCourseId(courseId, isPublicAPI ? 1 : 0, APIKey);

                    if (courseResult == null)
                    {
                        using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                        {
                            var entity = db.API_Course_GetById_v2(courseId, isPublicAPI ? 1 : 0, APIKey).ToList();

                            if (entity.Count > 0)
                            {
                                var entityCourse = entity[0];

                                Dictionary <string, string> categoryCodeList = CacheHelper.CategoryCodesList(isPublicAPI ? 1 : 0, APIKey);

                                courseResult = new Course
                                {
                                    Venues        = new List <Venue>(),
                                    Opportunities = new List <Opportunity>()
                                };

                                PopulateCourseDetails(categoryCodeList, entityCourse, courseResult);

                                PopulateProviderDetails(entityCourse, courseResult);

                                PopulateOpportunityDetails(entity, courseResult);

                                PopulateVenueDetails(courseResult);

                                CacheHelper.SaveCourseDetailsByCourseId(courseId, isPublicAPI ? 1 : 0, APIKey, courseResult);
                            }
                        }
                    }
                    courses.Add(courseResult);
                }

                new DBHelper().LogProviderRequestResponseLog(DBHelper.ServiceMethodName.GetCourseDetails, stopwatch.ElapsedMilliseconds, DBHelper.Serialize(courseIds), DBHelper.Serialize(courses), isPublicAPI, APIKey, courses.Count);

                return(courses);
            }
            catch (Exception ex)
            {
                LogException(ex, "GetCourseDetails");
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Called from "Get Providers" Service Method.
        /// </summary>
        /// <param name="providerSearchKeyword">string name to be searched against provider</param>
        /// <param name="APIKey"></param>
        /// <returns></returns>
        public List <Provider> GetProviders(string providerSearchKeyword, String APIKey)
        {
            try
            {
                var     stopwatch   = Stopwatch.StartNew();
                Boolean isPublicAPI = ConfigurationManager.AppSettings["IncludeUCASData"].ToLower() != "true";
                if (isPublicAPI && String.IsNullOrEmpty(APIKey.Trim()))
                {
                    return(null);
                }

                var providers = CacheHelper.GetProvidersByName(providerSearchKeyword, isPublicAPI ? 1 : 0, APIKey);

                if (providers == null)
                {
                    var filteredSearchKeyword = new DBHelper().LoadStopWordFilteredList(providerSearchKeyword);

                    using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                    {
                        providers = db.API_Provider_GetAll_v2(isPublicAPI ? 1 : 0, APIKey)
                                    .Where(p => (
                                               p.ProviderName.RemoveLeadingAndTrailingSymbols().Split(' ').Intersect(filteredSearchKeyword, StringComparer.OrdinalIgnoreCase).Count() >= filteredSearchKeyword.Count()
                                               ||
                                               p.ProviderNameAlias.RemoveLeadingAndTrailingSymbols().Split(' ').Intersect(filteredSearchKeyword, StringComparer.OrdinalIgnoreCase).Count() >= filteredSearchKeyword.Count()
                                               ) && !filteredSearchKeyword.Count().Equals(0))
                                    .Select(p => new Provider
                        {
                            ProviderId    = p.ProviderId.ToString(),
                            ProviderName  = p.ProviderName,
                            AddressLine1  = p.AddressLine1,
                            AddressLine2  = p.AddressLine2,
                            Town          = p.Town,
                            County        = p.County,
                            Postcode      = p.Postcode,
                            Phone         = p.Telephone,
                            Email         = p.Email,
                            Website       = p.Website,
                            Ukprn         = p.Ukprn.ToString(),
                            Upin          = p.UPIN.HasValue ? p.UPIN.ToString() : string.Empty,
                            TFPlusLoans   = p.Loans24Plus,
                            DFE1619Funded = p.DFE1619Funded
                        })
                                    .ToList();
                    }

                    CacheHelper.SaveProvider(providerSearchKeyword, isPublicAPI ? 1 : 0, APIKey, providers);
                }

                new DBHelper().LogProviderRequestResponseLog(DBHelper.ServiceMethodName.GetProviders, stopwatch.ElapsedMilliseconds, DBHelper.Serialize(providerSearchKeyword), DBHelper.Serialize(providers), isPublicAPI, APIKey, providers.Count);

                return(providers);
            }
            catch (Exception ex)
            {
                LogException(ex, "GetProviders");
                throw;
            }
        }
        private void PopulateCourseDetails(Dictionary <string, string> categoryCodeList, API_Course_GetById_v2_Result entityCourse, Course course)
        {
            course.CourseId           = entityCourse.CourseId;
            course.CourseTitle        = entityCourse.CourseTitle;
            course.QualificationType  = entityCourse.QualificationTypeRef;
            course.QualificationLevel = entityCourse.Qualification_Level;
            course.LdcsCode1          = entityCourse.LDCS1;
            course.LdcsCode2          = entityCourse.LDCS2;
            course.LdcsCode3          = entityCourse.LDCS3;
            course.LdcsCode4          = entityCourse.LDCS4;
            course.LdcsCode5          = entityCourse.LDCS5;
            course.LdcsDesc1          = GetLdscDescription(entityCourse.LDCS1, categoryCodeList);
            course.LdcsDesc2          = GetLdscDescription(entityCourse.LDCS2, categoryCodeList);
            course.LdcsDesc3          = GetLdscDescription(entityCourse.LDCS3, categoryCodeList);
            course.LdcsDesc4          = GetLdscDescription(entityCourse.LDCS4, categoryCodeList);
            course.LdcsDesc5          = GetLdscDescription(entityCourse.LDCS5, categoryCodeList);
            course.TariffRequired     = entityCourse.UcasTariffPoints.HasValue ? entityCourse.UcasTariffPoints.Value.ToString() : "";

            course.CourseSummary     = entityCourse.CourseSummary;
            course.AwardingBody      = entityCourse.AwardingOrganisationName;
            course.AssessmentMethod  = entityCourse.AssessmentMethod;
            course.BookingUrl        = entityCourse.BookingUrl;
            course.CreditValue       = entityCourse.UcasTariffPoints.HasValue ? entityCourse.UcasTariffPoints.Value.ToString() : string.Empty;
            course.DataType          = entityCourse.QualificationDataType;
            course.EntryRequirements = entityCourse.EntryRequirements;
            course.EquipmentRequired = entityCourse.EquipmentRequired;
            course.LadId             = entityCourse.LearningAimRef;
            course.QualificationReferenceAuthority = entityCourse.QualificationRefAuthority;
            course.QualificationReference          = entityCourse.QualificationRef;
            course.QualificationTitle = entityCourse.QualificationTitle;
            course.Url      = entityCourse.Url;
            course.DataType = entityCourse.QualificationDataType;

            if (!string.IsNullOrEmpty(entityCourse.LearningAimRef))
            {
                using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                {
                    var larEntity = db.API_LearningAim_GetById(entityCourse.LearningAimRef).ToList().FirstOrDefault();

                    if (larEntity != null)
                    {
                        course.AccreditationEndDate         = larEntity.AccreditationEndDate.HasValue ? larEntity.AccreditationEndDate.Value.ToString("dd/MM/yyyy") : string.Empty;
                        course.ERAppStatus                  = larEntity.ErAppStatus;
                        course.ERTtgStatus                  = larEntity.ErTtgStatus;
                        course.IndependentLivingSkills      = larEntity.IndepLivingSkills;
                        course.Level2EntitlementDescription = larEntity.Level2EntitlementCatDesc;
                        course.Level3EntitlementDescription = larEntity.Level3EntitlementCatDesc;
                        course.OtherFundingNonFundedStatus  = larEntity.OtherfundingNonFundedStatus;
                        course.QcaGuidedLearningHours       = larEntity.QcaGlh;
                        course.SectorLeadBodyDescription    = larEntity.SectorLeadBodyDesc;
                        course.SkillsForLifeFlag            = larEntity.SkillsForLife;
                        course.SkillsForLifeTypeDescription = larEntity.SkillsForLife;
                        course.TariffRequired               = entityCourse.UcasTariffPoints.HasValue ? entityCourse.UcasTariffPoints.ToString() : "";
                        course.AdultLRStatus                = larEntity.AdultlrStatus;
                    }
                }
            }
        }
        public ActionResult Delete(String stopword)
        {
            SFA_SearchAPIEntities searchAPIEntities = new SFA_SearchAPIEntities();

            searchAPIEntities.Configuration.EnsureTransactionsForFunctionsAndCommands = false; // Cannot be in a transaction
            searchAPIEntities.DropStopWord(stopword);

            ShowGenericSavedMessage();

            return(RedirectToAction("Index"));
        }
        // GET: StopWord
        public ActionResult Index()
        {
            ListStopWordsModel    model             = new ListStopWordsModel();
            SFA_SearchAPIEntities searchAPIEntities = new SFA_SearchAPIEntities();

            foreach (String stopWord in searchAPIEntities.GetStopWords())
            {
                model.Items.Add(new ListStopWordsItemModel(stopWord));
            }
            return(View(model));
        }
Пример #6
0
        /// <summary>
        /// Called by "Get Provider Details" Service Method.
        /// </summary>
        /// <param name="providerId">Provider Id from provider table</param>
        /// <param name="APIKey"></param>
        /// <returns></returns>
        public Provider GetProviderDetails(string providerId, String APIKey)
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                Boolean isPublicAPI = ConfigurationManager.AppSettings["IncludeUCASData"].ToLower() != "true";
                if (isPublicAPI && String.IsNullOrEmpty(APIKey.Trim()))
                {
                    return(null);
                }

                int formattedProviderId;
                int.TryParse(providerId, out formattedProviderId);

                var searchedProvider = CacheHelper.GetProviderById(formattedProviderId, isPublicAPI ? 1 : 0, APIKey);

                if (searchedProvider == null)
                {
                    using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                    {
                        searchedProvider = db.API_Provider_GetByProviderId_v2(formattedProviderId, isPublicAPI ? 1 : 0, APIKey)
                                           .Select(p => new Provider
                        {
                            ProviderId    = p.ProviderId.ToString(),
                            ProviderName  = p.ProviderName,
                            AddressLine1  = p.AddressLine1,
                            AddressLine2  = p.AddressLine2,
                            Town          = p.Town,
                            County        = p.County,
                            Postcode      = p.Postcode,
                            Phone         = p.Telephone,
                            Email         = p.Email,
                            Website       = p.Website,
                            Ukprn         = p.Ukprn.ToString(),
                            Upin          = p.UPIN.HasValue ? p.UPIN.ToString() : string.Empty,
                            TFPlusLoans   = p.Loans24Plus,
                            DFE1619Funded = p.DFE1619Funded
                        })
                                           .FirstOrDefault();
                    }
                    CacheHelper.SaveProviderById(formattedProviderId, isPublicAPI ? 1 : 0, APIKey, searchedProvider);
                }

                new DBHelper().LogProviderRequestResponseLog(DBHelper.ServiceMethodName.GetProviderDetails, stopwatch.ElapsedMilliseconds, DBHelper.Serialize(providerId), DBHelper.Serialize(searchedProvider), isPublicAPI, APIKey, searchedProvider == null ? 0 : 1);

                return(searchedProvider);
            }
            catch (Exception ex)
            {
                LogException(ex, "GetProviderDetails");
                throw;
            }
        }
 private static void Log(string request, string response, int timeInMilliseconds, ServiceMethodName methodName, Boolean isPublicAPI, String APIKey, Int32 recordCount)
 {
     try
     {
         using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
         {
             db.ProviderRequestResponesLog_Insert_v2(methodName.ToString(), request, response, timeInMilliseconds, isPublicAPI, APIKey, recordCount);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //swallow the exception
     }
 }
        public Dictionary <string, string> LoadCategoryCodes(Int32 isPublicAPI, String APIKey)
        {
            var result = new Dictionary <string, string>();

            using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
            {
                var categoryCodes = db.API_CategoryCode_GetAll_v2(isPublicAPI, APIKey).ToList();
                foreach (var categoryCode in categoryCodes)
                {
                    if (!result.ContainsKey(categoryCode.CategoryCodeName))
                    {
                        result.Add(categoryCode.CategoryCodeName, categoryCode.Description);
                    }
                }
            }
            return(result);
        }
        private static List <string> LoadStopWords()
        {
            var stopwords = CacheHelper.StopWords;

            if (stopwords == null)
            {
                using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                {
                    stopwords = db.StopWords
                                .Select(s => s.StopWordName.ToLower())
                                .ToList();
                }

                CacheHelper.AddStopwords(stopwords);
            }

            return(stopwords);
        }
        public ActionResult Add(AddStopWordModel model)
        {
            SFA_SearchAPIEntities searchAPIEntities = new SFA_SearchAPIEntities();

            if (searchAPIEntities.GetStopWords().Any(x => x == model.StopWord))
            {
                ModelState.AddModelError("StopWord", AppGlobal.Language.GetText(this, "StopWordAlreadyExists", "Stop word already exists"));
            }

            if (ModelState.IsValid)
            {
                searchAPIEntities.Configuration.EnsureTransactionsForFunctionsAndCommands = false; // Cannot be in a transaction
                searchAPIEntities.AddStopWord(model.StopWord.Trim());
                ShowGenericSavedMessage();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        /// <summary>
        /// Get all categories from DB
        /// </summary>
        /// <returns></returns>
        public List <Category> GetCategories(String APIKey)
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                Boolean isPublicAPI = ConfigurationManager.AppSettings["IncludeUCASData"].ToLower() != "true";
                if (isPublicAPI && String.IsNullOrEmpty(APIKey.Trim()))
                {
                    return(new List <Category>());
                }

                List <Category> categoryCode = CacheHelper.GetCategories(APIKey);

                if (categoryCode == null)
                {
                    using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                    {
                        categoryCode = db.API_CategoryCode_GetAll_v2(isPublicAPI ? 1 : 0, APIKey).Select(x => new Category
                        {
                            CategoryCode       = x.CategoryCodeName,
                            Description        = x.Description,
                            ParentCategoryCode = x.ParentCategoryCode,
                            CourseCount        = x.TotalCourses,
                            Searchable         = x.IsSearchable ? "Y" : "N",
                            Level = x.Level.HasValue ? x.Level.Value : 1
                        }).ToList();
                    }

                    CacheHelper.SaveCategories(APIKey, categoryCode);
                }

                new DBHelper().LogProviderRequestResponseLog(DBHelper.ServiceMethodName.GetCategories, stopwatch.ElapsedMilliseconds, string.Empty, DBHelper.Serialize(categoryCode), isPublicAPI, APIKey, categoryCode.Count);

                return(categoryCode);
            }
            catch (Exception ex)
            {
                LogException(ex, "GetCategories");
                throw;
            }
        }
Пример #12
0
        private static void LogException(Exception ex, String method)
        {
            Log log = new Log
            {
                MachineName = Environment.MachineName,
                Method      = method,
                Details     = String.Format("{0}\r\rStack Trace: {1}", ex.Message, ex.StackTrace ?? String.Empty)
            };

            if (ex.InnerException != null)
            {
                log.Details += String.Format("\r\rInner Exception: {0}\r\rInner Stack Trace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace ?? String.Empty);
            }

            using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
            {
                db.Logs.Add(log);
                db.SaveChanges();
            }
        }
        private void PopulateVenueDetails(Course course)
        {
            Boolean isPublicAPI = ConfigurationManager.AppSettings["IncludeUCASData"].ToLower() != "true";

            //Populate Venue details//
            foreach (var opportunity in course.Opportunities)
            {
                using (SFA_SearchAPIEntities db = new SFA_SearchAPIEntities())
                {
                    var venueEntity = db.API_Venue_GetById((int)opportunity.VenueId, isPublicAPI ? 1 : 0).FirstOrDefault();

                    if (venueEntity != null)
                    {
                        if (!course.Venues.Any(c => c.VenueId.Equals(opportunity.VenueId)))
                        {
                            var venue = new Venue
                            {
                                VenueName    = venueEntity.VenueName,
                                AddressLine1 = venueEntity.AddressLine1,
                                AddressLine2 = venueEntity.AddressLine2,
                                Town         = venueEntity.Town,
                                County       = venueEntity.County,
                                Postcode     = venueEntity.Postcode,
                                Latitude     = venueEntity.Latitude.ToString(),
                                Longitude    = venueEntity.Longitude.ToString(),
                                Phone        = venueEntity.Telephone,
                                Email        = venueEntity.Email,
                                Website      = venueEntity.Website,
                                Fax          = venueEntity.Fax,
                                Facilities   = venueEntity.Facilities,
                                VenueId      = opportunity.VenueId
                            };
                            course.Venues.Add(venue);
                        }
                    }
                }
            }
        }
        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);
            }
        }