From 8c76d97d9fce48938f64c5a328100452940f738a Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 14 Jun 2024 17:39:14 +0100 Subject: [PATCH] 1.2.11.6 --- SaxoniteCoreWeb/Base/App/SaxSystem_Web.cs | 2 +- ...fUsgaDataLookup-ScheduledUsgaDataLookup.cs | 374 +++++++++++------- .../ReferenceGolfController-Ajax.cs | 191 +++++++++ .../Controllers/ReferenceGolfController.cs | 45 +++ .../Admin/Models/Model_ReferenceGolf.cs | 55 +++ .../Localisation/SaxAdminProperties.resx | 3 + SaxoniteStandardBase/Base/App/Sax-Version.cs | 2 +- SaxoniteStandardBase/Base/App/Sax.cs | 26 +- .../Base/App/SaxApplication_Base.cs | 4 +- SaxoniteStandardBase/Base/App/SaxSystem.cs | 11 + .../Base/Bus/Reference/SaxGolfUsgaCountry.cs | 6 + .../Base/Bus/Reference/SaxGolfUsgaCourse.cs | 5 + .../Base/Bus/Reference/SaxGolfUsgaProvince.cs | 4 + .../Config/appsettings.Machine.Sarand602.json | 12 +- .../SaxReferenceGolfMgr_Dbas-UsgaCountry.cs | 17 +- .../SaxReferenceGolfMgr_Dbas-UsgaCourse.cs | 50 ++- .../SaxReferenceGolfMgr_Dbas-UsgaFacility.cs | 36 +- .../SaxReferenceGolfMgr_Dbas-UsgaMarker.cs | 39 +- .../SaxReferenceGolfMgr_Dbas-UsgaProvince.cs | 15 +- SaxoniteWebApi/Api/App/SaxApplication_Api.cs | 55 +++ .../Api/Controllers/SystemController.cs | 4 + SaxoniteWebApi/Program.cs | 5 + 22 files changed, 745 insertions(+), 216 deletions(-) create mode 100644 SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController-Ajax.cs create mode 100644 SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController.cs create mode 100644 SaxoniteCoreWebAdmin/Admin/Models/Model_ReferenceGolf.cs diff --git a/SaxoniteCoreWeb/Base/App/SaxSystem_Web.cs b/SaxoniteCoreWeb/Base/App/SaxSystem_Web.cs index ac48ea3..5f02a38 100644 --- a/SaxoniteCoreWeb/Base/App/SaxSystem_Web.cs +++ b/SaxoniteCoreWeb/Base/App/SaxSystem_Web.cs @@ -42,7 +42,7 @@ namespace Saxonite.Net.Core.Web.Base.App /// Web: HttpContext.Current.Server.MachineName /// FQDN: System.Net.Dns.GetHostName() /// - private static void InitComputerName() + public static void InitComputerName() { try { diff --git a/SaxoniteCoreWeb/Base/Procs/SaxGolfUsgaDataLookup-ScheduledUsgaDataLookup.cs b/SaxoniteCoreWeb/Base/Procs/SaxGolfUsgaDataLookup-ScheduledUsgaDataLookup.cs index 70cc965..68d6e61 100644 --- a/SaxoniteCoreWeb/Base/Procs/SaxGolfUsgaDataLookup-ScheduledUsgaDataLookup.cs +++ b/SaxoniteCoreWeb/Base/Procs/SaxGolfUsgaDataLookup-ScheduledUsgaDataLookup.cs @@ -1,5 +1,7 @@ using DocumentFormat.OpenXml.Drawing.Diagrams; +using DocumentFormat.OpenXml.Office2016.Excel; using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Helpers; @@ -27,9 +29,9 @@ namespace Saxonite.Net.Core.Web.Base.Procs /// Determine which USGA data population process to run. /// - Method is invoked periodically (every 20 mins) by the Admin Hosted Service Console. /// - 1. Populate countries if not already done or not done for a while (eg. 24 hours). - /// - 2. Populate provinces for a Country that has none or occasionally to refresh one that has. - /// - 3. Populate Courses for a Province that has none or occasionally to refresh one that has. - /// - 4. Populate Courses for a Province that has none or occasionally to refresh one that has. + /// - 2. Populate provinces for a Country that has none or occasionally refresh one that has. + /// - 3. Populate Courses for a Province that has none or occasionally refresh one that has. + /// - 4. Populate Markers for a Course that has none or occasionally refresh one that has. /// public static void ExecuteScheduledUsgaDataLookup(SaxSessionContext sessionContext, DbUpdateInfo dbUpdateInfo, SacsTaskData taskData) { @@ -47,63 +49,62 @@ namespace Saxonite.Net.Core.Web.Base.Procs if (taskData.IsCancellationRequested) return; // Determine which process to run. - // Check USGA country population. - List usgaCountries = internals.ReferenceGolfMgr.GetUsgaCountryList(new SaxGolfUsgaCountry.Params()); - if (!usgaCountries.Any() || (DateTime.Now - usgaDataLookupControl.CountriesLastLookedUp).TotalHours > MathUtil.Constrain(Sax.Config.Admin.Processes.Scheduled.UsgaGolfDataLookup.HoursBetweenCountryLookup, 1, 24 * 7)) - { - // No countries currently found or long enough since last lookup. - // Lookup USGA countries. - List countriesData = usgaDataLookup.LookupUsgaCountries(); - SaLogger.Info($"{SysUtil.Fn} USGA Countries populated: {countriesData.Count}.", true); - usgaDataLookupControl.CountriesLastLookedUp = DateTime.Now; - return; - } - if (taskData.IsCancellationRequested) return; - // Population of Countries without Provinces is only allowed occasionally to avoid delaying population of lower data. - bool populateCountryWithNoProvinces = SacsRandomHelper.GetInt32(1, 7) == 1; - - // Check USGA Country Province population. - List usgaCountriesWithProvinces = new List(); - List usgaCountriesWithNoProvinces = new List(); - foreach (SaxGolfUsgaCountry usgaCountry in usgaCountries.OrderBy(item => item.Priority ? 0 : 1).ThenBy(_ => SacsRandomHelper.GetInt32(Int32.MaxValue))) + //----------------------------------------------------------- + // 1. Countries. { - SaxGolfUsgaProvince.Params prmUsgaProvince = new SaxGolfUsgaProvince.Params(); - prmUsgaProvince.CountryIdsIncluded.Add(usgaCountry.Id); - if (internals.ReferenceGolfMgr.GetUsgaProvinceCount(prmUsgaProvince) < 1) + // Check USGA country population. + List usgaCountries = internals.ReferenceGolfMgr.GetUsgaCountryList(new SaxGolfUsgaCountry.Params()); + if (!usgaCountries.Any() || (DateTime.Now - usgaDataLookupControl.CountriesLastLookedUp).TotalHours > MathUtil.Constrain(Sax.Config.Admin.Processes.Scheduled.UsgaGolfDataLookup.HoursBetweenCountryLookup, 1, 24 * 7)) { - usgaCountriesWithNoProvinces.Add(usgaCountry); - if (populateCountryWithNoProvinces) + // No countries currently found or long enough since last lookup. + // Lookup USGA countries. + List countriesData = usgaDataLookup.LookupUsgaCountries(); + SaLogger.Info($"{SysUtil.Fn} USGA Countries populated: {countriesData.Count}.", true); + usgaDataLookupControl.CountriesLastLookedUp = DateTime.Now; + return; + } + if (taskData.IsCancellationRequested) return; + } + + //----------------------------------------------------------- + // 2. Provinces. + + // 2a. Population of active priority Country with no Provinces. + { + bool populatePriorityCountryNoProvinces = SacsRandomHelper.GetInt32(1, 3) == 1; + if (populatePriorityCountryNoProvinces) + { + SaxGolfUsgaCountry.Params prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.False; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + List countriesNoProvinces = internals.ReferenceGolfMgr.GetUsgaCountryList(prmCountry).Randomise(); + disposableItems.AddRange(countriesNoProvinces); + if (countriesNoProvinces.Any()) { - // Country has no Provinces - look them up. + SaxGolfUsgaCountry usgaCountry = countriesNoProvinces[0]; List provincesData = usgaDataLookup.LookupUsgaProvincesForCountry(usgaCountry.CountryCode); SaLogger.Info($"{SysUtil.Fn} USGA Provinces populated for {usgaCountry.CountryCode} {usgaCountry.CountryName}" + (usgaCountry.Priority ? " [Priority]" : "") + $": {provincesData.Count}.", true); return; } } - else - { - // Country has Provinces. - usgaCountriesWithProvinces.Add(usgaCountry); - } - if (taskData.IsCancellationRequested) return; } - if (usgaCountriesWithProvinces.Any()) + // 2b. Refresh active priority Country with Provinces. { - // Pick the first (randomly sorted) Country. - SaxGolfUsgaCountry usgaCountry = usgaCountriesWithProvinces[0]; - - // One of the Countries with Provinces can have its list of provinces refreshed occasionally. - bool refreshCountryWithProvinces = SacsRandomHelper.GetInt32(1, 17) == 1; - if (refreshCountryWithProvinces) + bool refreshPriorityCountryWithProvinces = SacsRandomHelper.GetInt32(1, 3) == 1; + if (refreshPriorityCountryWithProvinces) { - SaxGolfUsgaProvince.Params prmUsgaProvince = new SaxGolfUsgaProvince.Params(); - prmUsgaProvince.CountryIdsIncluded.Add(usgaCountry.Id); - List usgaProvinces = internals.ReferenceGolfMgr.GetUsgaProvinceList(prmUsgaProvince).OrderBy(item => item.Priority ? 0 : 1).ThenBy(_ => SacsRandomHelper.GetInt32(Int32.MaxValue)).ToList(); - if (usgaProvinces.Any()) + SaxGolfUsgaCountry.Params prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.True; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + List countriesWithProvinces = internals.ReferenceGolfMgr.GetUsgaCountryList(prmCountry).Randomise(); + disposableItems.AddRange(countriesWithProvinces); + if (countriesWithProvinces.Any()) { - // Refresh Country Provinces. + SaxGolfUsgaCountry usgaCountry = countriesWithProvinces[0]; List provincesData = usgaDataLookup.LookupUsgaProvincesForCountry(usgaCountry.CountryCode); SaLogger.Info($"{SysUtil.Fn} USGA Provinces refreshed for {usgaCountry.CountryCode} {usgaCountry.CountryName}" + (usgaCountry.Priority ? " [Priority]" : "") + $": {provincesData.Count}.", true); return; @@ -111,112 +112,209 @@ namespace Saxonite.Net.Core.Web.Base.Procs } } - if (usgaCountriesWithProvinces.Any()) + //----------------------------------------------------------- + // 3. Courses. + + // 3a. Populate active priority Province with no Facilities (Courses). { - // Pick the first (randomly sorted) Country. - SaxGolfUsgaCountry usgaCountry = usgaCountriesWithProvinces[0]; - - // Population of Courses for Province without Facilities is allowed occasionally. - bool populateProvinceWithNoFacilities = SacsRandomHelper.GetInt32(1, 7) == 1; - - // Check USGA Province Course population. - List usgaProvincesWithFacilities = new List(); - List usgaProvincesWithNoFacilities = new List(); - SaxGolfUsgaProvince.Params prmUsgaProvince = new SaxGolfUsgaProvince.Params(); - prmUsgaProvince.CountryIdsIncluded.Add(usgaCountry.Id); - foreach (SaxGolfUsgaProvince usgaProvince in internals.ReferenceGolfMgr.GetUsgaProvinceList(prmUsgaProvince).OrderBy(item => item.Priority ? 0 : 1).ThenBy(_ => SacsRandomHelper.GetInt32(Int32.MaxValue))) + bool populatePriorityProvinceNoFacilities = SacsRandomHelper.GetInt32(1, 3) == 1; + if (populatePriorityProvinceNoFacilities) { - SaxGolfUsgaFacility.Params prmUsgaFacility = new SaxGolfUsgaFacility.Params(); - prmUsgaFacility.ProvinceIdsIncluded.Add(usgaProvince.Id); - if (internals.ReferenceGolfMgr.GetUsgaFacilityCount(prmUsgaFacility) < 1) + // Active priority Provinces with no Facilities. + SaxGolfUsgaProvince.Params prmProvince = new SaxGolfUsgaProvince.Params(); + prmProvince.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmProvince.HasFacilities = SacsHierarchyItem.Params.BoolState.False; + prmProvince.StatusCat = SaxGolfUsgaProvince.StatusCat.ActiveOnly; + List provincesNoFacilities = internals.ReferenceGolfMgr.GetUsgaProvinceList(prmProvince); + disposableItems.AddRange(provincesNoFacilities); + if (provincesNoFacilities.Any()) { - usgaProvincesWithNoFacilities.Add(usgaProvince); - if (populateProvinceWithNoFacilities) - { - // Province has no Facilities - look up the courses. - List coursesData = usgaDataLookup.LookupUsgaCoursesForCountryAndProvince(usgaCountry.CountryCode, usgaProvince.ProvinceCode); - SaLogger.Info($"{SysUtil.Fn} USGA Courses populated for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName}" + (usgaProvince.Priority ? " [Priority]" : "") + $": {coursesData.Count}.", true); - return; - } - } - else - { - // Country has provinces. - usgaProvincesWithFacilities.Add(usgaProvince); - } - if (taskData.IsCancellationRequested) return; - } - - if (usgaProvincesWithFacilities.Any()) - { - // Pick the first (randomly sorted) province. - SaxGolfUsgaProvince usgaProvince = usgaProvincesWithFacilities[0]; - - // Population of Courses for Province with Facilities is allowed occasionally. - bool populateProvinceWithFacilities = SacsRandomHelper.GetInt32(1, 17) == 1; - if (populateProvinceWithFacilities) - { - // Refresh Courses for Province with Facilities. - List coursesData = usgaDataLookup.LookupUsgaCoursesForCountryAndProvince(usgaCountry.CountryCode, usgaProvince.ProvinceCode); - SaLogger.Info($"{SysUtil.Fn} USGA Courses refreshed for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName}" + (usgaProvince.Priority ? " [Priority]" : "") + $": {coursesData.Count}.", true); - return; - } - - // Compile list of Courses for this province. - SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params(); - prmCourse.ProvinceIdsIncluded.Add(usgaProvince.Id); - List usgaCourses = internals.ReferenceGolfMgr.GetUsgaCourseList(prmCourse).OrderBy(item => item.Priority ? 0 : 1).ThenBy(_ => SacsRandomHelper.GetInt32(Int32.MaxValue)).ToList(); - List usgaCoursesWithMarkers = new List(); - foreach (SaxGolfUsgaCourse usgaCourse in usgaCourses) - { - SaxGolfUsgaMarker.Params prmMarker = new SaxGolfUsgaMarker.Params(); - prmMarker.CourseIdsIncluded.Add(usgaCourse.Id); - if (internals.ReferenceGolfMgr.GetUsgaMarkerCount(prmMarker) == 0) - { - // Populate Markers for first course without markers. - List markersData = usgaDataLookup.LookupUsgaMarkersForCourse(usgaCourse.CourseId); - SaLogger.Info($"{SysUtil.Fn} USGA Markers populated for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName} - {usgaCourse.Caption} [Id: {usgaCourse.CourseId}" + (usgaCourse.Priority ? ", Priority" : "") + $"]: {markersData.Count}.", true); - return; - } - else usgaCoursesWithMarkers.Add(usgaCourse); - } - if (usgaCoursesWithMarkers.Any()) - { - // Populate Markers for first course with markers. - SaxGolfUsgaCourse usgaCourse = usgaCoursesWithMarkers[0]; - List markersData = usgaDataLookup.LookupUsgaMarkersForCourse(usgaCourse.CourseId); - SaLogger.Info($"{SysUtil.Fn} USGA Markers refreshed for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName} - {usgaCourse.Caption} [Id: {usgaCourse.CourseId}" + (usgaCourse.Priority ? ", Priority" : "") + $"]: {markersData.Count}.", true); - return; - } - } - - // Fallback - populate Courses for Province. - bool allowFallbackCoursePopulation = true; - if (allowFallbackCoursePopulation) - { - SaxGolfUsgaProvince usgaProvince = usgaProvincesWithNoFacilities.Any() ? usgaProvincesWithNoFacilities[0] : usgaProvincesWithFacilities.Any() ? usgaProvincesWithFacilities[0] : null; - if (usgaCountry != null && usgaProvince != null && usgaCountry.Id.Equals(usgaProvince.CountryId)) - { - List coursesData = usgaDataLookup.LookupUsgaCoursesForCountryAndProvince(usgaCountry.CountryCode, usgaProvince.ProvinceCode); - SaLogger.Info($"{SysUtil.Fn} USGA Courses populated for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName}" + (usgaProvince.Priority ? " [Priority]" : "") + $": {coursesData.Count}. [Fallback]", true); + // Province has no Facilities - populate courses. + SaxGolfUsgaProvince usgaProvince = provincesNoFacilities[0]; + List coursesData = LookupUsgaCourses(internals, usgaDataLookup, usgaProvince, false); return; } } } - // Fallback - populate provinces for country. - bool allowFallbackProvincePopulation = true; - if (allowFallbackProvincePopulation) + // 3b. Refresh active priority Province with Facilities (courses). + { + bool refreshProvinceWithFacilities = SacsRandomHelper.GetInt32(1, 3) == 1; + if (refreshProvinceWithFacilities) + { + SaxGolfUsgaProvince.Params prmProvince = new SaxGolfUsgaProvince.Params(); + prmProvince.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmProvince.HasFacilities = SacsHierarchyItem.Params.BoolState.True; + prmProvince.StatusCat = SaxGolfUsgaProvince.StatusCat.ActiveOnly; + List provincesWithFacilities = internals.ReferenceGolfMgr.GetUsgaProvinceList(prmProvince); + disposableItems.AddRange(provincesWithFacilities); + if (provincesWithFacilities.Any()) + { + SaxGolfUsgaProvince usgaProvince = provincesWithFacilities[0]; + List coursesData = LookupUsgaCourses(internals, usgaDataLookup, usgaProvince, true); + return; + } + } + } + + //----------------------------------------------------------- + // 4. Markers. + + // 4a. Populate active priority Course with no Markers. + { + bool populatePriorityCourseNoMarkers = SacsRandomHelper.GetInt32(1, 2) == 1; + if (populatePriorityCourseNoMarkers) + { + SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params(); + prmCourse.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCourse.HasMarkers = SacsHierarchyItem.Params.BoolState.False; + prmCourse.StatusCat = SaxGolfUsgaCourse.StatusCat.ActiveOnly; + List coursesNoMarkers = internals.ReferenceGolfMgr.GetUsgaCourseList(prmCourse); + disposableItems.AddRange(coursesNoMarkers); + if (coursesNoMarkers.Any()) + { + SaxGolfUsgaCourse usgaCourse = coursesNoMarkers[0]; + List markersData = LookupUsgaMarkers(internals, usgaDataLookup, usgaCourse, false); + return; + } + } + } + + // 4b. Refresh active priority Course with Markers. + { + bool refreshPriorityCourseWithMarkers = SacsRandomHelper.GetInt32(1, 3) == 1; + if (refreshPriorityCourseWithMarkers) + { + // Active priority Course with no Markers. + SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params(); + prmCourse.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCourse.HasMarkers = SacsHierarchyItem.Params.BoolState.True; + prmCourse.StatusCat = SaxGolfUsgaCourse.StatusCat.ActiveOnly; + List coursesWithMarkers = internals.ReferenceGolfMgr.GetUsgaCourseList(prmCourse); + disposableItems.AddRange(coursesWithMarkers); + if (coursesWithMarkers.Any()) + { + // Refresh first Course with Markers. + SaxGolfUsgaCourse usgaCourse = coursesWithMarkers[0]; + List markersData = LookupUsgaMarkers(internals, usgaDataLookup, usgaCourse, true); + return; + } + } + } + + //----------------------------------------------------------- + // 5. Fallback population. + + // 5a. Active Country with no Provinces. + { + bool populateCountryNoProvinces = SacsRandomHelper.GetInt32(1, 2) == 1; + if (populateCountryNoProvinces) + { + SaxGolfUsgaCountry.Params prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.False; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + List countriesNoProvinces = internals.ReferenceGolfMgr.GetUsgaCountryList(prmCountry).Randomise(); + disposableItems.AddRange(countriesNoProvinces); + if (countriesNoProvinces.Any()) + { + SaxGolfUsgaCountry usgaCountry = countriesNoProvinces[0]; + List provincesData = usgaDataLookup.LookupUsgaProvincesForCountry(usgaCountry.CountryCode); + SaLogger.Info($"{SysUtil.Fn} USGA Provinces populated for {usgaCountry.CountryCode} {usgaCountry.CountryName} [Fallback]: {provincesData.Count}.", true); + return; + } + } + } + + // 5b. Active Province with no Facilities (courses). + { + bool populateProvinceNoFacilities = SacsRandomHelper.GetInt32(1, 3) == 1; + if (populateProvinceNoFacilities) + { + // Active Provinces with no Facilities. + SaxGolfUsgaProvince.Params prmProvince = new SaxGolfUsgaProvince.Params(); + prmProvince.HasFacilities = SacsHierarchyItem.Params.BoolState.False; + prmProvince.StatusCat = SaxGolfUsgaProvince.StatusCat.ActiveOnly; + List provincesNoFacilities = internals.ReferenceGolfMgr.GetUsgaProvinceList(prmProvince); + disposableItems.AddRange(provincesNoFacilities); + if (provincesNoFacilities.Any()) + { + // Province has no Facilities - populate courses. + SaxGolfUsgaProvince usgaProvince = provincesNoFacilities[0]; + List coursesData = LookupUsgaCourses(internals, usgaDataLookup, usgaProvince, false, true); + return; + } + } + } + + // 5c. Populate active Course with no Markers. + { + bool populateCourseNoMarkers = SacsRandomHelper.GetInt32(1, 2) == 1; + if (populateCourseNoMarkers) + { + SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params(); + prmCourse.HasMarkers = SacsHierarchyItem.Params.BoolState.False; + prmCourse.StatusCat = SaxGolfUsgaCourse.StatusCat.ActiveOnly; + List coursesNoMarkers = internals.ReferenceGolfMgr.GetUsgaCourseList(prmCourse); + disposableItems.AddRange(coursesNoMarkers); + if (coursesNoMarkers.Any()) + { + SaxGolfUsgaCourse usgaCourse = coursesNoMarkers[0]; + List markersData = LookupUsgaMarkers(internals, usgaDataLookup, usgaCourse, false, true); + return; + } + } + } + + //----------------------------------------------------------- + + SaLogger.Warn($"{SysUtil.Fn} No data population task found to execute."); + + //----------------------------------------------------------- + } + } + + //------------------------------------------------------------------- + private static List LookupUsgaCourses(SaxInternals internals, SaxGolfUsgaDataLookup usgaDataLookup, SaxGolfUsgaProvince usgaProvince, bool refresh, bool fallback = false) + { + List coursesData = new List(); + SaxGolfUsgaCountry usgaCountry = internals.ReferenceGolfMgr.GetUsgaCountryById(usgaProvince.CountryId); + if (usgaCountry != null) + { + coursesData = usgaDataLookup.LookupUsgaCoursesForCountryAndProvince(usgaCountry.CountryCode, usgaProvince.ProvinceCode); + List annotations = new List(); + if (usgaProvince.Priority) annotations.Add("Priority"); + if (fallback) annotations.Add("Fallback"); + SaLogger.Info($"{SysUtil.Fn} USGA Courses refreshed for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName}" + (annotations.Any() ? $" [{annotations.Concat(", ")}]" : "") + $": {coursesData.Count}.", true); + } + else SaLogger.Error($"{SysUtil.Fn} USGA Country not found for Id {usgaProvince.CountryId} for Province {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName}."); + return coursesData; + } + + //------------------------------------------------------------------- + private static List LookupUsgaMarkers(SaxInternals internals, SaxGolfUsgaDataLookup usgaDataLookup, SaxGolfUsgaCourse usgaCourse, bool refresh, bool fallback = false) + { + SaxGolfUsgaFacility usgaFacility = internals.ReferenceGolfMgr.GetUsgaFacilityById(usgaCourse.FacilityId); + SaxGolfUsgaProvince usgaProvince = internals.ReferenceGolfMgr.GetUsgaProvinceById(usgaFacility?.ProvinceId); + SaxGolfUsgaCountry usgaCountry = internals.ReferenceGolfMgr.GetUsgaCountryById(usgaProvince?.CountryId); + List markersData = new List(); + if (usgaFacility != null) + { + if (usgaProvince != null) { - SaxGolfUsgaCountry usgaCountry = usgaCountriesWithNoProvinces.Any() ? usgaCountriesWithNoProvinces[0] : usgaCountriesWithProvinces.Any() ? usgaCountriesWithProvinces[0] : null; if (usgaCountry != null) { - List provincesData = usgaDataLookup.LookupUsgaProvincesForCountry(usgaCountry.CountryCode); - SaLogger.Info($"{SysUtil.Fn} USGA Provinces populated for {usgaCountry.CountryCode} {usgaCountry.CountryName}" + (usgaCountry.Priority ? " [Priority]" : "") + $": {provincesData.Count}. [Fallback]", true); - return; + markersData = usgaDataLookup.LookupUsgaMarkersForCourse(usgaCourse.CourseId); + List annotations = new List(); + if (usgaCourse.Priority) annotations.Add("Priority"); + if (fallback) annotations.Add("Fallback"); + SaLogger.Info($"{SysUtil.Fn} USGA Markers " + (refresh ? "refreshed" : "populated") + $" for {usgaCountry.CountryCode} {usgaCountry.CountryName} - {usgaProvince.ProvinceCode} {usgaProvince.ProvinceName} - {usgaCourse.Caption} [Id: {usgaCourse.CourseId}" + (annotations.Any() ? $"{annotations.Concat("",", ")}" : "") + $"]: {markersData.Count}.", true); } + else SaLogger.Error($"{SysUtil.Fn} Missing Country for Province {usgaProvince.ProvinceName}. Country Id: {usgaProvince.CountryId}."); } + else SaLogger.Error($"{SysUtil.Fn} Missing Province for Facility {usgaFacility.FacilityName}. Province Id: {usgaFacility.ProvinceId}."); } + else SaLogger.Error($"{SysUtil.Fn} Missing Facility for Course {usgaCourse.FullName}. Facility Id: {usgaCourse.FacilityId}."); + return markersData; } //------------------------------------------------------------------- diff --git a/SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController-Ajax.cs b/SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController-Ajax.cs new file mode 100644 index 0000000..0e3e14b --- /dev/null +++ b/SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController-Ajax.cs @@ -0,0 +1,191 @@ +using Microsoft.AspNetCore.Mvc; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; +using Saxonite.Net.Core.Web.Admin.Models; +using Saxonite.Net.Standard.Base.App; +using Saxonite.Net.Standard.Base.Bus; +using Saxonite.Net.Standard.Base.Bus.Reference; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Saxonite.Net.Core.Web.Admin.Controllers +{ + //======================================================================= + // Reference Golf Controller - Ajax requests. + //======================================================================= + partial class ReferenceGolfController + { + //------------------------------------------------------------------- + // USGA Country data. + private class UsgaCountryStatsData : AjaxResponse_Base + { + public long? Total { get; set; } + public long? Active { get; set; } + public long? Inactive { get; set; } + public long? Deleted { get; set; } + public long? PriorityNoProvinces { get; set; } + public long? NonPriorityNoProvinces { get; set; } + public long? PriorityWithProvinces { get; set; } + public long? NonPriorityWithProvinces { get; set; } + } + private class UsgaCountryListData : AjaxResponse_Data.ItemData_Base + { + public String Code { get; set; } + public String Name { get; set; } + public bool? PriorityProvincePopulate { get; set; } + public long? ProvinceCount { get; set; } + public long? ProvinceCountActive { get; set; } + } + private class UsgaCountryItemData : UsgaCountryListData + { + } + private void PopulateUsgaCountryResponseListData(SaxGolfUsgaCountry country, UsgaCountryListData data) + { + data.Id = SysId.ToString(country.Id); + data.Code = country.CountryCode; + data.Name = country.CountryName; + data.StatusCode = country.StatusCode; + data.StatusDesc = country.StatusDesc; + } + private void PopulateUsgaCountryResponseItemData(SaxGolfUsgaCountry country, UsgaCountryItemData data) + { + PopulateUsgaCountryResponseListData(country, data); + } + + //------------------------------------------------------------------- + private void PopulateCountryStatsData(UsgaCountryStatsData countryStats) + { + // All countries. + SaxGolfUsgaCountry.Params prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.Any; + countryStats.Total = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Active countries. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countryStats.Active = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Inctive countries. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.InactiveOnly; + countryStats.Inactive = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Deleted countries. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.DeletedOnly; + countryStats.Deleted = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Priority countries without provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.False; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countryStats.PriorityNoProvinces = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Non-Priority countries without provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.False; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.False; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countryStats.NonPriorityNoProvinces = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Priority countries with provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.True; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countryStats.PriorityWithProvinces = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + + // Non-Priority countries with provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.False; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.True; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countryStats.NonPriorityWithProvinces = ReferenceGolfMgr.GetUsgaCountryCount(prmCountry); + } + + //------------------------------------------------------------------- + // Get ReferenceGolf List ajax request. + //------------------------------------------------------------------- + private class AjaxResponse_ReferenceGolfList : AjaxResponse_Data + { + // Construction. + public AjaxResponse_ReferenceGolfList(SaxModel_Admin model) : base(model) { } + // ReferenceGolf list. + public List Countries { get; } = new List(); + } + //------------------------------------------------------------------- + [HttpPost] + [Route("ReferenceGolf/Ajax/GetUsgaCountryList")] + [Route("ReferenceGolf/Ajax/GetUsgaCountryies")] + public IActionResult Ajax_GetUsgaCountryList(Model_ReferenceGolf model) + { + String fn = GetType().Name + ".Ajax_GetUsgaCountryList"; + String messageTitle = Localiser["caption.reference.golf"]; + AjaxResponse_ReferenceGolfList responseData = new AjaxResponse_ReferenceGolfList(model); + + // Validate session. + if (!ValidUserSession) + return GetAjaxResult_InvalidSession(responseData); + + // Item filter. + SaxGolfUsgaCountry.Params prmUsgaCountry = new SaxGolfUsgaCountry.Params(); + prmUsgaCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.Any; + model.Paging.ItemTotal = (ulong)ReferenceGolfMgr.GetUsgaCountryCount(prmUsgaCountry); + model.PopulatePagingTo(prmUsgaCountry.ResultsPaging); + + // Item columns. + ColumnDfn colId = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.Id); + ColumnDfn colCode = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.CountryCode); + ColumnDfn colName = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.CountryName); + ColumnDfn colProvinceCount_All = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.ProvinceCount_All); + ColumnDfn colProvinceCount_Active = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.ProvinceCount_Active); + ColumnDfn colFlags = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.Flags); + ColumnDfn colStatus = ReferenceGolfMgr.GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column.Status); + List columns = new List() + { + colId, colCode, colName, colProvinceCount_All, colProvinceCount_Active, colFlags, colStatus + }; + + // Sort order. + prmUsgaCountry.SortColumns.Add(colName); + + // Query items. + using (DbResultSet resultSet = ReferenceGolfMgr.ExecuteUsgaCountryQuery(columns, prmUsgaCountry)) + { + while (resultSet != null && resultSet.HasRows && resultSet.NextRecord()) + { + NamedValue.Map values = resultSet.GetRecordValues(); + ushort flags = (ushort)values.GetLong(colFlags.DataName); + UsgaCountryListData countryData = new UsgaCountryListData() + { + Id = values.GetString(colId.DataName), + Code = values.GetString(colName.DataName), + Name = values.GetString(colName.DataName), + ProvinceCount = values.GetLong(colProvinceCount_All.DataName), + ProvinceCountActive = values.GetLong(colProvinceCount_Active.DataName), + PriorityProvincePopulate = SacsHierarchyItem.GetFlag(flags, SaxGolfUsgaCountry.Flag_Priority), + StatusCode = values.GetString(colStatus.DataName), + StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName)) + }; + responseData.Countries.Add(countryData); + } + } + if (model.Paging.IsPaged) + model.Paging.ItemCount = (ushort)responseData.Countries.Count; + + // Complete response. + responseData.SetPaging(model); + responseData.Success = true; + return Json(responseData); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController.cs b/SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController.cs new file mode 100644 index 0000000..7400392 --- /dev/null +++ b/SaxoniteCoreWebAdmin/Admin/Controllers/ReferenceGolfController.cs @@ -0,0 +1,45 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Saxonite.Net.Core.Web.Admin.Models; +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Core.Web.Base.Controllers; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; + +namespace Saxonite.Net.Core.Web.Admin.Controllers +{ + //======================================================================= + public partial class ReferenceGolfController : SaxController_Admin + { + //------------------------------------------------------------------- + // Construction. + public ReferenceGolfController(SaxLocaliser localiser, ILogger logger) : + base(localiser, logger) + { + } + + //------------------------------------------------------------------- + [HttpGet] + public IActionResult Index() + { + // Validate session. + if (!ValidUserSession) + AutoLoginUser(); + if (!ValidUserSession) + return RedirectToAction("", ""); + + // Paging. + Model_ReferenceGolf model = new Model_ReferenceGolf(Localiser); + model.Paging.PageNo = 1; + model.Paging.PageLength = 12; + + return View(model); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebAdmin/Admin/Models/Model_ReferenceGolf.cs b/SaxoniteCoreWebAdmin/Admin/Models/Model_ReferenceGolf.cs new file mode 100644 index 0000000..e33e19e --- /dev/null +++ b/SaxoniteCoreWebAdmin/Admin/Models/Model_ReferenceGolf.cs @@ -0,0 +1,55 @@ +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Utils; +using Saxonite.Base.App; +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Core.Web.Base.Controllers; +using Saxonite.Net.Core.Web.Base.Models; +using Saxonite.Net.Standard.Base.App; +using Saxonite.Net.Standard.Base.Bus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Saxonite.Net.Core.Web.Admin.Models +{ + //======================================================================= + public class Model_ReferenceGolf : SaxModel_Admin + { + //------------------------------------------------------------------- + // Construction. + public Model_ReferenceGolf(SaxLocaliser localiser) : + base(localiser) + { + AdditionalFiles_JS.Add("js/sax-ref-golf.js"); + } + + //------------------------------------------------------------------- + // Reference Golf list parameters. + public class FilterData + { + } + public FilterData Filter { get; } = new FilterData(); + + //------------------------------------------------------------------- + // Reference Golf properties. + + //------------------------------------------------------------------- + // Validation. + //------------------------------------------------------------------- + // Reference Golf. + public bool ValidateReferenceGolfData(SaxController_Base.AjaxResponse_Data responseData) + { + // Record disposable items as they are created so all can be disposed when needed. + using (DisposableCollection disposableItems = new DisposableCollection()) + { + } + return !responseData.HasControlErrors(); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SaxoniteCoreWebAdmin/Localisation/SaxAdminProperties.resx b/SaxoniteCoreWebAdmin/Localisation/SaxAdminProperties.resx index 612ac5d..867d3ce 100644 --- a/SaxoniteCoreWebAdmin/Localisation/SaxAdminProperties.resx +++ b/SaxoniteCoreWebAdmin/Localisation/SaxAdminProperties.resx @@ -159,6 +159,9 @@ Organisations + + Reference - Golf + Upload Organisations diff --git a/SaxoniteStandardBase/Base/App/Sax-Version.cs b/SaxoniteStandardBase/Base/App/Sax-Version.cs index cf03a37..99e0307 100644 --- a/SaxoniteStandardBase/Base/App/Sax-Version.cs +++ b/SaxoniteStandardBase/Base/App/Sax-Version.cs @@ -18,7 +18,7 @@ namespace Saxonite.Net.Standard.Base.App //------------------------------------------------------------------- public static class Version { - private static String version { get; } = "1.2.11.5"; + private static String version { get; } = "1.2.11.6"; // Retrieve version. public static String GetFullVersion () { return version; } public static String GetAppVersion () diff --git a/SaxoniteStandardBase/Base/App/Sax.cs b/SaxoniteStandardBase/Base/App/Sax.cs index 0306779..0d4e3fb 100644 --- a/SaxoniteStandardBase/Base/App/Sax.cs +++ b/SaxoniteStandardBase/Base/App/Sax.cs @@ -50,6 +50,23 @@ namespace Saxonite.Net.Standard.Base.App Admin = 900, } + //------------------------------------------------------------------- + public enum Environment + { + Development = 0, + Staging = 50, + Production = 90, + } + + //------------------------------------------------------------------- + public enum InstanceType + { + Prod, + UAT, + QC, + Dev + } + //------------------------------------------------------------------- public enum Database { @@ -59,15 +76,6 @@ namespace Saxonite.Net.Standard.Base.App Support = 90, } - //------------------------------------------------------------------- - public enum InstanceType - { - Production, - UAT, - QC, - Dev - } - //------------------------------------------------------------------- /// Yes or No option. public enum YesNo diff --git a/SaxoniteStandardBase/Base/App/SaxApplication_Base.cs b/SaxoniteStandardBase/Base/App/SaxApplication_Base.cs index f2fb44b..d824110 100644 --- a/SaxoniteStandardBase/Base/App/SaxApplication_Base.cs +++ b/SaxoniteStandardBase/Base/App/SaxApplication_Base.cs @@ -35,8 +35,8 @@ namespace Saxonite.Net.Standard.Base.App public abstract IDatabaseInfo CreateDbInfo(SaxSessionContext sessionContext, Sax.Database databaseType); // Application instance. public abstract Sax.InstanceType InstanceType { get; } - public bool IsLiveHost() { return InstanceType == Sax.InstanceType.Production; } - public bool IsTestHost() { return InstanceType != Sax.InstanceType.Production; } + public bool IsLiveHost() { return InstanceType == Sax.InstanceType.Prod; } + public bool IsTestHost() { return InstanceType != Sax.InstanceType.Prod; } public bool IsDevHost() { return InstanceType == Sax.InstanceType.Dev; } public abstract String EnvironmentName { get; } // Email configuration. diff --git a/SaxoniteStandardBase/Base/App/SaxSystem.cs b/SaxoniteStandardBase/Base/App/SaxSystem.cs index 4a894ea..668f932 100644 --- a/SaxoniteStandardBase/Base/App/SaxSystem.cs +++ b/SaxoniteStandardBase/Base/App/SaxSystem.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Text; using Saxonite.Net.Standard.Base.Mgr.Support; using Saxonite.Net.Standard.Base.Mgr.Reference; +using Sarand.Net.Standard.Base.Utils; namespace Saxonite.Net.Standard.Base.App { @@ -22,6 +23,16 @@ namespace Saxonite.Net.Standard.Base.App { } + //------------------------------------------------------------------- + // Environment. + //------------------------------------------------------------------- + public static Sax.Environment GetEnvironment() + { + if (ComputerName.ContainsCI("Sarand")) + return Sax.Environment.Development; + return Sax.Environment.Production; + } + //------------------------------------------------------------------- // Business components. //------------------------------------------------------------------- diff --git a/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCountry.cs b/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCountry.cs index af705f6..cb31019 100644 --- a/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCountry.cs +++ b/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCountry.cs @@ -27,6 +27,8 @@ namespace Saxonite.Net.Standard.Base.Bus.Reference EntCountryCode, CountryName, // Associated data. + ProvinceCount_All, + ProvinceCount_Active, // Common. Notes, Flags, @@ -201,6 +203,10 @@ namespace Saxonite.Net.Standard.Base.Bus.Reference public String CountryCodeFull { get; set; } public String CountryNameFull { get; set; } public String CountryNamePartial { get; set; } + // Flags. + public FlagState PriorityFlagState { get; set; } = FlagState.Either; + // Associated data. + public BoolState HasProvinces { get; set; } = BoolState.Either; // Common properties. public String NotesPartial { get; set; } public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly; diff --git a/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCourse.cs b/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCourse.cs index 8bd0628..10a8793 100644 --- a/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCourse.cs +++ b/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaCourse.cs @@ -373,6 +373,11 @@ namespace Saxonite.Net.Standard.Base.Bus.Reference public String CourseFilter { get; set; } public String CourseNameFull { get; set; } public String CourseNamePartial { get; set; } + public BoolState HasMarkersData { get; set; } = BoolState.Either; + // Flags. + public FlagState PriorityFlagState { get; set; } = FlagState.Either; + // Associated data. + public BoolState HasMarkers { get; set; } = BoolState.Either; // Common properties. public String NotesPartial { get; set; } public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly; diff --git a/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaProvince.cs b/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaProvince.cs index adba697..47c1ccc 100644 --- a/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaProvince.cs +++ b/SaxoniteStandardBase/Base/Bus/Reference/SaxGolfUsgaProvince.cs @@ -216,6 +216,10 @@ namespace Saxonite.Net.Standard.Base.Bus.Reference public String ProvinceCodeFull { get; set; } public String ProvinceNameFull { get; set; } public String ProvinceNamePartial { get; set; } + // Flags. + public FlagState PriorityFlagState { get; set; } = FlagState.Either; + // Associated data. + public BoolState HasFacilities { get; set; } = BoolState.Either; // Common properties. public String NotesPartial { get; set; } public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly; diff --git a/SaxoniteStandardBase/Resources/Config/appsettings.Machine.Sarand602.json b/SaxoniteStandardBase/Resources/Config/appsettings.Machine.Sarand602.json index 9b17d6c..eced78a 100644 --- a/SaxoniteStandardBase/Resources/Config/appsettings.Machine.Sarand602.json +++ b/SaxoniteStandardBase/Resources/Config/appsettings.Machine.Sarand602.json @@ -1,8 +1,8 @@ { "AppConfigs": { "SAX-Prod": { - "Environments": [ "Production" ], - "Instance": "", + "Environments": [ "Production", "Demo", "Staging" ], + "Instance": "Demo", "URLs": { "Online": { "Root": "https://sportierre.com/" @@ -62,13 +62,13 @@ }, "Variants": [ { - "ApplicationRootFolder": "C:\\Sarand\\Saxonite\\Demo", - "Instance": "Demo", + "ApplicationRootFolder": "C:\\Sarand\\Saxonite\\Prod", + "Instance": "Prod", "Documents": { - "RootFolder": "C:\\Sarand\\Saxonite\\Demo\\Docs" + "RootFolder": "C:\\Sarand\\Saxonite\\Prod\\Docs" }, "Logging": { - "RootFolder": "C:\\Sarand\\Saxonite\\Demo\\Logs" + "RootFolder": "C:\\Sarand\\Saxonite\\Prod\\Logs" } } ] diff --git a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCountry.cs b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCountry.cs index 147ee68..f678cf8 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCountry.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCountry.cs @@ -403,7 +403,7 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference // Item Ids. if (prm.IdsIncluded.HasValidIds()) filter.Add($"{col_Id} IN ({prm.IdsIncluded.Concat(",")})"); - if (prm.IdsExcluded.HasValidIds() ) + if (prm.IdsExcluded.HasValidIds()) filter.Add($"{col_Id} NOT IN ({prm.IdsExcluded.Concat(",")})"); // Country code. @@ -431,15 +431,26 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference if (!StringUtil.IsEmpty(prm.CountryNamePartial)) filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_CountryName, aliasUsgaCountry)} LIKE '%{DbQuery.FormatForLike(prm.CountryNamePartial)}%'"); + // Flags. + if (prm.PriorityFlagState != SacsHierarchyItem.Params.FlagState.Either) + filter.Add(DbQuery.BuildBitMappedFilter(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_Flags, aliasUsgaCountry), SaxGolfUsgaCountry.Flag_Priority, prm.PriorityFlagState == SacsHierarchyItem.Params.FlagState.True)); + + // Associated data. + if (prm.HasProvinces != SacsHierarchyItem.Params.BoolState.Either) + { + String existsPrefix = (prm.HasProvinces == SacsHierarchyItem.Params.BoolState.True ? "" : "Not "); + filter.Add($"{existsPrefix} Exists (Select 1 From {SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaProvince)} Where {SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaProvince_CountryId)}={col_Id})"); + } + // Notes. if (!StringUtil.IsEmpty(prm.NotesPartial)) filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_Notes, aliasUsgaCountry)} LIKE '%{DbQuery.FormatForLike(prm.NotesPartial)}%'"); // Status. if (prm.StatusCat != SaxGolfUsgaCountry.StatusCat.Any) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_Status, aliasUsgaCountry) + GetUsgaCountryStatusCatFilterCondition(prm.StatusCat)); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_Status, aliasUsgaCountry)} {GetUsgaCountryStatusCatFilterCondition(prm.StatusCat)}"); - if (filter.Count < 1) filter.Add("1=1"); + if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1"); return filter; } internal static String GetUsgaCountryStatusCatFilterCondition(SaxGolfUsgaCountry.StatusCat statusCat) diff --git a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCourse.cs b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCourse.cs index 7b53e2a..6d50011 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCourse.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaCourse.cs @@ -1,4 +1,5 @@ -using Sarand.Net.Standard.Base.App; +using DocumentFormat.OpenXml.Office2016.Excel; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; @@ -494,6 +495,7 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference List filter = new List(); String col_Id = SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Id, aliasUsgaCourse); String col_FacilityId = SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_FacilityId, aliasUsgaCourse); + String col_CourseName = SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_CourseName, aliasUsgaCourse); // Item Ids. if (prm.IdsIncluded.HasValidIds()) @@ -528,42 +530,60 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference foreach (String filterWord in filterWords) { List articleFilter = new List(); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_CourseName, aliasUsgaCourse) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_FullName, aliasUsgaCourse) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Address1, aliasUsgaCourse) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Address2, aliasUsgaCourse) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_City, aliasUsgaCourse) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); + articleFilter.Add($"{col_CourseName} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_FullName, aliasUsgaCourse)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Address1, aliasUsgaCourse)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Address2, aliasUsgaCourse)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_City, aliasUsgaCourse)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); filter.Add(articleFilter.Concat(" OR ", "(", ")")); } } // Name. if (!StringUtil.IsEmpty(prm.CourseNameFull)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_CourseName, aliasUsgaCourse) + "='" + DbQuery.FormatForCondition(prm.CourseNameFull) + "'"); + filter.Add($"{col_CourseName}='{DbQuery.FormatForCondition(prm.CourseNameFull)}'"); if (!StringUtil.IsEmpty(prm.CourseNamePartial)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_CourseName, aliasUsgaCourse) + " LIKE '%" + DbQuery.FormatForLike(prm.CourseNamePartial) + "%'"); + filter.Add($"{col_CourseName} LIKE '%{DbQuery.FormatForLike(prm.CourseNamePartial)}%'"); + + // Markers data. + if (prm.HasMarkersData != SacsHierarchyItem.Params.BoolState.Either) + { + String lenComparison = (prm.HasMarkers == SacsHierarchyItem.Params.BoolState.True ? ">0" : "<1"); + filter.Add($"Len(LTrim(RTrim(IsNull({SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker)})))){lenComparison}"); + } + + // Flags. + if (prm.PriorityFlagState != SacsHierarchyItem.Params.FlagState.Either) + filter.Add(DbQuery.BuildBitMappedFilter(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Flags, aliasUsgaCourse), SaxGolfUsgaCourse.Flag_Priority, prm.PriorityFlagState == SacsHierarchyItem.Params.FlagState.True)); + + // Associated data. + if (prm.HasMarkers!= SacsHierarchyItem.Params.BoolState.Either) + { + String existsPrefix = (prm.HasMarkers== SacsHierarchyItem.Params.BoolState.True ? "" : "Not "); + filter.Add($"{existsPrefix} Exists (Select 1 From {SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker)} Where {SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId)}={col_Id})"); + } // Notes. if (!StringUtil.IsEmpty(prm.NotesPartial)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Notes, aliasUsgaCourse) + " LIKE '%" + DbQuery.FormatForLike(prm.NotesPartial) + "%'"); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Notes, aliasUsgaCourse)} LIKE '%{DbQuery.FormatForLike(prm.NotesPartial)}%'"); // Status. if (prm.StatusCat != SaxGolfUsgaCourse.StatusCat.Any) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Status, aliasUsgaCourse) + GetUsgaCourseStatusCatFilterCondition(prm.StatusCat)); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Status, aliasUsgaCourse)} {GetUsgaCourseStatusCatFilterCondition(prm.StatusCat)}"); - if (filter.Count < 1) filter.Add("1=1"); + if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1"); return filter; } internal static String GetUsgaCourseStatusCatFilterCondition(SaxGolfUsgaCourse.StatusCat statusCat) { if (statusCat == SaxGolfUsgaCourse.StatusCat.ActiveOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Active) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Active)}'"; if (statusCat == SaxGolfUsgaCourse.StatusCat.InactiveOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Inactive) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Inactive)}'"; if (statusCat == SaxGolfUsgaCourse.StatusCat.NotDeleted) - return "!='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return $"!='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'"; if (statusCat == SaxGolfUsgaCourse.StatusCat.DeletedOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'"; return ""; } // Item sort columns. diff --git a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaFacility.cs b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaFacility.cs index 4d9a561..edfb52b 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaFacility.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaFacility.cs @@ -448,19 +448,17 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference public override List GetUsgaFacilityQueryFilter(SaxGolfUsgaFacility.Params prm) { List filter = new List(); + String col_Id = SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Id, aliasUsgaFacility); // Item Ids. - String idsIncluded = prm.IdsIncluded.Concat(","); - if (!idsIncluded.IsEmpty()) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Id, aliasUsgaFacility) + " IN (" + idsIncluded + ")"); - String idsExcluded = prm.IdsExcluded.Concat(","); - if (!idsExcluded.IsEmpty()) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Id, aliasUsgaFacility) + " NOT IN (" + idsExcluded + ")"); + if (prm.IdsIncluded.HasValidIds()) + filter.Add($"{col_Id} IN ({prm.IdsIncluded.Concat(",")})"); + if (prm.IdsExcluded.HasValidIds()) + filter.Add($"{col_Id} NOT IN ({prm.IdsExcluded.Concat(",")})"); // Countries. - String provinceIdsIncluded = prm.ProvinceIdsIncluded.Concat(","); - if (!provinceIdsIncluded.IsEmpty()) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_ProvinceId, aliasUsgaFacility) + " IN (" + provinceIdsIncluded + ")"); + if (prm.ProvinceIdsIncluded.HasValidIds()) + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_ProvinceId, aliasUsgaFacility)} IN ({prm.ProvinceIdsIncluded.Concat(",")})"); if (!StringUtil.IsBlank(prm.FacilityFilter)) { @@ -471,38 +469,38 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference foreach (String filterWord in filterWords) { List articleFilter = new List(); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_FacilityName, aliasUsgaFacility) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_FacilityName, aliasUsgaFacility)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); filter.Add(articleFilter.Concat(" OR ", "(", ")")); } } // Name. if (!StringUtil.IsEmpty(prm.FacilityNameFull)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_FacilityName, aliasUsgaFacility) + "='" + DbQuery.FormatForCondition(prm.FacilityNameFull) + "'"); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_FacilityName, aliasUsgaFacility)}='{DbQuery.FormatForCondition(prm.FacilityNameFull)}'"); if (!StringUtil.IsEmpty(prm.FacilityNamePartial)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_FacilityName, aliasUsgaFacility) + " LIKE '%" + DbQuery.FormatForLike(prm.FacilityNamePartial) + "%'"); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_FacilityName, aliasUsgaFacility)} LIKE '%{DbQuery.FormatForLike(prm.FacilityNamePartial)}%'"); // Notes. if (!StringUtil.IsEmpty(prm.NotesPartial)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Notes, aliasUsgaFacility) + " LIKE '%" + DbQuery.FormatForLike(prm.NotesPartial) + "%'"); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Notes, aliasUsgaFacility)} LIKE '%{DbQuery.FormatForLike(prm.NotesPartial)}%'"); // Status. if (prm.StatusCat != SaxGolfUsgaFacility.StatusCat.Any) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Status, aliasUsgaFacility) + GetUsgaFacilityStatusCatFilterCondition(prm.StatusCat)); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_Status, aliasUsgaFacility)} {GetUsgaFacilityStatusCatFilterCondition(prm.StatusCat)}"); - if (filter.Count < 1) filter.Add("1=1"); + if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1"); return filter; } internal static String GetUsgaFacilityStatusCatFilterCondition(SaxGolfUsgaFacility.StatusCat statusCat) { if (statusCat == SaxGolfUsgaFacility.StatusCat.ActiveOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Active) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Active)}'"; if (statusCat == SaxGolfUsgaFacility.StatusCat.InactiveOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Inactive) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Inactive)}'"; if (statusCat == SaxGolfUsgaFacility.StatusCat.NotDeleted) - return "!='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return $"!='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'"; if (statusCat == SaxGolfUsgaFacility.StatusCat.DeletedOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'"; return ""; } // Item sort columns. diff --git a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaMarker.cs b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaMarker.cs index 91deb1d..abb0b72 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaMarker.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaMarker.cs @@ -494,19 +494,17 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference public override List GetUsgaMarkerQueryFilter(SaxGolfUsgaMarker.Params prm) { List filter = new List(); + String col_Id = SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, aliasUsgaMarker); // Item Ids. - String idsIncluded = prm.IdsIncluded.Concat(","); - if (!idsIncluded.IsEmpty()) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, aliasUsgaMarker) + " IN (" + idsIncluded + ")"); - String idsExcluded = prm.IdsExcluded.Concat(","); - if (!idsExcluded.IsEmpty()) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, aliasUsgaMarker) + " NOT IN (" + idsExcluded + ")"); + if (prm.IdsIncluded.HasValidIds()) + filter.Add($"{col_Id} IN ({prm.IdsIncluded.Concat(",")})"); + if (prm.IdsExcluded.HasValidIds()) + filter.Add($"{col_Id} NOT IN ({prm.IdsExcluded.Concat(",")})"); // Countries. - String courseIdsIncluded = prm.CourseIdsIncluded.Concat(","); - if (!courseIdsIncluded.IsEmpty()) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId, aliasUsgaMarker) + " IN (" + courseIdsIncluded + ")"); + if (prm.CourseIdsIncluded.HasValidIds()) + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId, aliasUsgaMarker)} IN ({prm.CourseIdsIncluded.Concat(",")})"); if (!StringUtil.IsBlank(prm.MarkerFilter)) { @@ -517,34 +515,35 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference foreach (String filterWord in filterWords) { List articleFilter = new List(); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Caption, aliasUsgaMarker) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption, aliasUsgaMarker) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Tee, aliasUsgaMarker) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); - articleFilter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender, aliasUsgaMarker) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Caption, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Tee, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); + articleFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'"); filter.Add(articleFilter.Concat(" OR ", "(", ")")); } } + // Notes. if (!StringUtil.IsEmpty(prm.NotesPartial)) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Notes, aliasUsgaMarker) + " LIKE '%" + DbQuery.FormatForLike(prm.NotesPartial) + "%'"); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Notes, aliasUsgaMarker)} LIKE '%{DbQuery.FormatForLike(prm.NotesPartial)}%'"); // Status. if (prm.StatusCat != SaxGolfUsgaMarker.StatusCat.Any) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, aliasUsgaMarker) + GetUsgaMarkerStatusCatFilterCondition(prm.StatusCat)); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, aliasUsgaMarker)} {GetUsgaMarkerStatusCatFilterCondition(prm.StatusCat)}"); - if (filter.Count < 1) filter.Add("1=1"); + if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1"); return filter; } internal static String GetUsgaMarkerStatusCatFilterCondition(SaxGolfUsgaMarker.StatusCat statusCat) { if (statusCat == SaxGolfUsgaMarker.StatusCat.ActiveOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Active) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Active)}'"; if (statusCat == SaxGolfUsgaMarker.StatusCat.InactiveOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Inactive) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Inactive)}'"; if (statusCat == SaxGolfUsgaMarker.StatusCat.NotDeleted) - return "!='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return $"!='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'"; if (statusCat == SaxGolfUsgaMarker.StatusCat.DeletedOnly) - return "='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'"; + return $"='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'"; return ""; } // Item sort columns. diff --git a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaProvince.cs b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaProvince.cs index 626cfb9..4fae730 100644 --- a/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaProvince.cs +++ b/SaxoniteStandardDbas/Dbas/Mgr/Reference/SaxReferenceGolfMgr_Dbas-UsgaProvince.cs @@ -455,15 +455,26 @@ namespace Saxonite.Net.Standard.Dbas.Mgr.Reference if (!StringUtil.IsEmpty(prm.ProvinceNamePartial)) filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaProvince_ProvinceName, aliasUsgaProvince)} LIKE '%{DbQuery.FormatForLike(prm.ProvinceNamePartial)}%'"); + // Flags. + if (prm.PriorityFlagState != SacsHierarchyItem.Params.FlagState.Either) + filter.Add(DbQuery.BuildBitMappedFilter(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaProvince_Flags, aliasUsgaProvince), SaxGolfUsgaProvince.Flag_Priority, prm.PriorityFlagState == SacsHierarchyItem.Params.FlagState.True)); + + // Associated data. + if (prm.HasFacilities != SacsHierarchyItem.Params.BoolState.Either) + { + String existsPrefix = (prm.HasFacilities == SacsHierarchyItem.Params.BoolState.True ? "" : "Not "); + filter.Add($"{existsPrefix} Exists (Select 1 From {SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaFacility)} Where {SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaFacility_ProvinceId)}={col_Id})"); + } + // Notes. if (!StringUtil.IsEmpty(prm.NotesPartial)) filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaProvince_Notes, aliasUsgaProvince)} LIKE '%{DbQuery.FormatForLike(prm.NotesPartial)}%'"); // Status. if (prm.StatusCat != SaxGolfUsgaProvince.StatusCat.Any) - filter.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaProvince_Status, aliasUsgaProvince) + GetUsgaProvinceStatusCatFilterCondition(prm.StatusCat)); + filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaProvince_Status, aliasUsgaProvince)} {GetUsgaProvinceStatusCatFilterCondition(prm.StatusCat)}"); - if (filter.Count < 1) filter.Add("1=1"); + if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1"); return filter; } internal static String GetUsgaProvinceStatusCatFilterCondition(SaxGolfUsgaProvince.StatusCat statusCat) diff --git a/SaxoniteWebApi/Api/App/SaxApplication_Api.cs b/SaxoniteWebApi/Api/App/SaxApplication_Api.cs index bc91b09..6f0f543 100644 --- a/SaxoniteWebApi/Api/App/SaxApplication_Api.cs +++ b/SaxoniteWebApi/Api/App/SaxApplication_Api.cs @@ -1,6 +1,7 @@ using Microsoft.Identity.Client; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Helpers; using Sarand.Net.Standard.Base.IO; @@ -10,6 +11,7 @@ using Saxonite.Net.Core.Web.Base.App; using Saxonite.Net.Core.Web.Base.Helpers; using Saxonite.Net.Core.Web.Base.Procs; using Saxonite.Net.Standard.Base.App; +using Saxonite.Net.Standard.Base.Bus.Reference; using Saxonite.Net.Standard.Base.Consoles; using Saxonite.Net.Standard.Base.Helpers; using Saxonite.Web.Api.Consoles; @@ -141,6 +143,59 @@ namespace Saxonite.Web.Api.App // Allows you to bypass "AuthenticationException: The remote certificate is invalid according to the validation procedure." error. Don't to do this in production code... //ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; + if (false) + { + // USGA statistics. + using (DisposableCollection disposableItems = new DisposableCollection()) + { + var refGolfMgr = System.CreateReferenceGolfMgr(SessionContext, null); + disposableItems.Add(refGolfMgr); + + // All countries. + SaxGolfUsgaCountry.Params prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.Any; + List countries = refGolfMgr.GetUsgaCountryList(prmCountry); + disposableItems.AddRange(countries); + SaLogger.Info($"{SysUtil.Fn} Countries: {countries.Count}"); + + // Priority countries without provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.False; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countries = refGolfMgr.GetUsgaCountryList(prmCountry); + disposableItems.AddRange(countries); + SaLogger.Info($"{SysUtil.Fn} Priority Countries without provinces: {countries.Count}"); + + // Non-Priority countries without provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.False; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.False; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countries = refGolfMgr.GetUsgaCountryList(prmCountry); + disposableItems.AddRange(countries); + SaLogger.Info($"{SysUtil.Fn} Non-Priority Countries without provinces: {countries.Count}"); + + // Priority countries with provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.True; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.True; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countries = refGolfMgr.GetUsgaCountryList(prmCountry); + disposableItems.AddRange(countries); + SaLogger.Info($"{SysUtil.Fn} Priority Countries with provinces: {countries.Count}"); + + // Non-Priority countries with provinces. + prmCountry = new SaxGolfUsgaCountry.Params(); + prmCountry.PriorityFlagState = SacsHierarchyItem.Params.FlagState.False; + prmCountry.HasProvinces = SacsHierarchyItem.Params.BoolState.True; + prmCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.ActiveOnly; + countries = refGolfMgr.GetUsgaCountryList(prmCountry); + disposableItems.AddRange(countries); + SaLogger.Info($"{SysUtil.Fn} Non-Priority Countries with provinces: {countries.Count}"); + } + } + if (false) { CancellationToken cancelToken = new CancellationToken(); diff --git a/SaxoniteWebApi/Api/Controllers/SystemController.cs b/SaxoniteWebApi/Api/Controllers/SystemController.cs index fb6e743..61581aa 100644 --- a/SaxoniteWebApi/Api/Controllers/SystemController.cs +++ b/SaxoniteWebApi/Api/Controllers/SystemController.cs @@ -53,6 +53,8 @@ namespace Saxonite.Web.Api.Controllers { public String? Version { get; set; } public String? Environment { get; set; } + public String? Instance { get; set; } + public String? ConfigLogFolder { get; set; } public String? LogFolder { get; set; } public String? EmailContext { get; set; } } @@ -71,6 +73,8 @@ namespace Saxonite.Web.Api.Controllers ResponseData_Config responseData = new ResponseData_Config(); responseData.Config.Version = Sax.Version.GetFullVersion(); responseData.Config.Environment = SaxApplication_Api.AppInstance?.EnvironmentName; + responseData.Config.Instance = SaxApplication_Api.AppInstance?.InstanceType.ToString(); + responseData.Config.ConfigLogFolder = SaxApplication_Api.AppInstance?.AppConfig.Logging.RootFolder; responseData.Config.LogFolder = SaLogger.LogFolder; responseData.Config.EmailContext = SaxApplication_Api.AppInstance?.EmailConfig.Context; return responseData; diff --git a/SaxoniteWebApi/Program.cs b/SaxoniteWebApi/Program.cs index eecb35b..27591f2 100644 --- a/SaxoniteWebApi/Program.cs +++ b/SaxoniteWebApi/Program.cs @@ -1,3 +1,5 @@ +using Saxonite.Net.Core.Web.Base.App; +using Saxonite.Net.Standard.Base.App; using Saxonite.Web.Api.App; using System.Text.Json.Serialization; @@ -5,6 +7,9 @@ using System.Text.Json.Serialization; var builder = WebApplication.CreateBuilder(args); + SaxSystem_Web.InitComputerName(); + builder.Environment.EnvironmentName = SaxSystem.GetEnvironment().ToString(); + // Add services to the container. builder.Services.AddControllers();