This commit is contained in:
2024-06-14 17:39:14 +01:00
parent 60427e8230
commit 8c76d97d9f
22 changed files with 745 additions and 216 deletions
@@ -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<UsgaCountryListData> Countries { get; } = new List<UsgaCountryListData>();
}
//-------------------------------------------------------------------
[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<ColumnDfn> columns = new List<ColumnDfn>()
{
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);
}
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -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<HomeController> 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);
}
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -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<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
{
}
return !responseData.HasControlErrors();
}
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -159,6 +159,9 @@
<data name="caption.organisations" xml:space="preserve">
<value>Organisations</value>
</data>
<data name="caption.reference.golf" xml:space="preserve">
<value>Reference - Golf</value>
</data>
<data name="caption.upload.organisations" xml:space="preserve">
<value>Upload Organisations</value>
</data>