148 lines
6.9 KiB
C#
148 lines
6.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Sacs.Web.Components;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Email;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using Saxonite.Net.Standard.Base.Consoles;
|
|
using Saxonite.Net.Standard.Base.Mgr;
|
|
using Saxonite.Net.Standard.Base.Mgr.Reference;
|
|
using Saxonite.Net.Standard.Base.Mgr.Support;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Saxonite.Net.Core.Web.Base.Controllers
|
|
{
|
|
//=======================================================================
|
|
public abstract class SaxController_Base : SaController
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private SaxInternals internals;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Protected construction.
|
|
protected SaxController_Base(SaxLocaliser localiser)
|
|
{
|
|
Localiser = localiser;
|
|
|
|
// Initialise console (debug) logging listener.
|
|
//if (Directory.Exists(App.LoggingRootFolder) && SaxSystem.DebugMode)
|
|
// SaxConsoleListener.ConfigureDebugListener(App.LoggingRootFolder);
|
|
if (DebugMode) SaLogger.Trace($"{GetType().Name}.CTR");
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
protected SaxApplication_Web App { get { return SaxApplication_Web.WebApp; } }
|
|
public SaxAppConfig AppConfig { get { return App.AppConfig; } }
|
|
public SaxSessionContext SessionContext { get { return App.SessionContext; } }
|
|
public SaxLocaliser Localiser { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Globals.
|
|
protected SaxConsoleHelper ConsoleHelper { get { return SaxGlobals.ConsoleHelper; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Business components.
|
|
public SaxInternals Internals { get { if (internals == null) internals = new SaxInternals(SessionContext); return internals; } }
|
|
// Consoles.
|
|
public SaxDataCacheConsole DataCacheConsole { get { return Internals.DataCacheConsole; } }
|
|
public SaxSessionDataConsole SessionDataConsole { get { return Internals.SessionDataConsole; } }
|
|
public SaxActivityConsole ActivityConsole { get { return Internals.ActivityConsole; } }
|
|
// Managers.
|
|
public SaxReferenceMgr ReferenceMgr { get { return Internals.ReferenceMgr; } }
|
|
public SaxAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
|
public SaxActivityMgr ActivityMgr { get { return Internals.ActivityMgr; } }
|
|
public SaxItemDataMgr ItemDataMgr { get { return Internals.ItemDataMgr; } }
|
|
public SaxReferenceGolfMgr ReferenceGolfMgr { get { return Internals.ReferenceGolfMgr; } }
|
|
public SaxSupportMgr SupportMgr { get { return Internals.SupportMgr; } }
|
|
// System codes.
|
|
public List<TypeCodeDesc> DataItemTypeCodes { get { return Internals.DataItemTypeCodes; } }
|
|
public List<TypeCodeDesc> SportGroupingCodes { get { return Internals.SportGroupingCodes; } }
|
|
public List<TypeCodeDesc> SportSpecialityLabelCodes { get { return Internals.SportSpecialityLabelCodes; } }
|
|
public List<TypeCodeDesc> SportContactTypeCodes { get { return Internals.SportContactTypeCodes; } }
|
|
public List<TypeCodeDesc> SportParticipatingCodes { get { return Internals.SportParticipatingCodes; } }
|
|
public List<TypeCodeDesc> SportPreparingCodes { get { return Internals.SportPreparingCodes; } }
|
|
public List<TypeCodeDesc> SportOfficiatingCodes { get { return Internals.SportOfficiatingCodes; } }
|
|
public List<TypeCodeDesc> RegionTypeCodes { get { return Internals.RegionTypeCodes; } }
|
|
public List<TypeCodeDesc> EligibilityTypeCodes { get { return Internals.EligibilityTypeCodes; } }
|
|
public List<TypeCodeDesc> UserRoleCodes { get { return Internals.UserRoleCodes; } }
|
|
public List<TypeCodeDesc> OrganisationTypeCodes { get { return Internals.OrganisationTypeCodes; } }
|
|
public List<TypeCodeDesc> OrganisationCategoryCodes { get { return Internals.OrganisationCategoryCodes; } }
|
|
public List<TypeCodeDesc> OrganisationRoleCodes { get { return Internals.OrganisationRoleCodes; } }
|
|
public List<TypeCodeDesc> AssociationTypeCodes { get { return Internals.AssociationTypeCodes; } }
|
|
public List<TypeCodeDesc> AddressTypeCodes { get { return Internals.AddressTypeCodes; } }
|
|
public List<TypeCodeDesc> ContactMethodCodes { get { return Internals.ContactMethodCodes; } }
|
|
public List<TypeCodeDesc> EventTypeCodes { get { return Internals.EventTypeCodes; } }
|
|
public List<TypeCodeDesc> OpportunityTypeCodes { get { return Internals.OpportunityTypeCodes; } }
|
|
public List<TypeCodeDesc> ActivityReactionCodes { get { return Internals.ActivityReactionCodes; } }
|
|
// Support.
|
|
public List<TypeCodeDesc> UserReportTypeCodes { get { return Internals.UserReportTypeCodes; } }
|
|
// Email.
|
|
public SaEmailConfig EmailConfig { get { return App.EmailConfig; } }
|
|
public SaxEmailConsole EmailConsole { get { return Internals.EmailConsole; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
[NonAction]
|
|
/// <summary>
|
|
/// Retrieve sport by matching the name and include groups as required.
|
|
/// </summary>
|
|
/// <param name="sportName"></param>
|
|
/// <param name="includeGroups"></param>
|
|
/// <returns>List of matching sports.</returns>
|
|
public List<SaxSport.Data> GetSportsByName(String sportName, bool includeGroups = false)
|
|
{
|
|
List<SaxSport.Data> sportsData = new List<SaxSport.Data>();
|
|
if (DataCacheConsole != null)
|
|
{
|
|
List<SaxSport.Data> allSports = DataCacheConsole.GetActiveSports();
|
|
foreach (SaxSport.Data sport in allSports.Where(item => item.Name.EqualsCI(sportName)))
|
|
{
|
|
sportsData.Add(sport);
|
|
if (!includeGroups) continue;
|
|
foreach (SaxSport.Data sportParent in allSports.Where(item => item.Id.Equals(sport.SportIdParent)))
|
|
sportsData.Add(sportParent);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Data cache is not available.
|
|
// Query direct from the database (Admin).
|
|
Dictionary<SysId, SaxSport> sports = new Dictionary<SysId, SaxSport>();
|
|
|
|
// Sport by name.
|
|
SaxSport.Params prmSport = new SaxSport.Params();
|
|
prmSport.NameFull = sportName;
|
|
sports.AddRange(ReferenceMgr.GetSportList(prmSport).ToDictionary(item => item.Id));
|
|
|
|
if (includeGroups)
|
|
{
|
|
// Parent sports.
|
|
prmSport = new SaxSport.Params();
|
|
prmSport.IdsIncluded.AddIds(sports.Values.Where(item => SysId.IsValid(item.SportIdParent)).Select(item => item.SportIdParent));
|
|
if (prmSport.IdsIncluded.Any())
|
|
sports.AddRange(ReferenceMgr.GetSportList(prmSport).ToDictionary(item => item.Id));
|
|
}
|
|
sportsData = sports.Values.Select(item => item.GetData()).ToList();
|
|
}
|
|
return sportsData;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|