313 lines
10 KiB
C#
313 lines
10 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Saxonite.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
// Organisation.
|
|
//=======================================================================
|
|
public abstract class SaxOrganisation : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
Name,
|
|
OrganisationType,
|
|
OrganisationType_Desc,
|
|
OrganisationCategory,
|
|
OrganisationCategory_Desc,
|
|
PhoneMain,
|
|
PhoneAlt,
|
|
// Sport.
|
|
SportId,
|
|
Sport_Name,
|
|
// Region.
|
|
RegionId,
|
|
Region_Name,
|
|
// Associated data.
|
|
/// <summary>Number of users with an active interest in the organisation.</summary>
|
|
User_Count,
|
|
/// <summary>Number of users who are 'members' of the organisation.</summary>
|
|
Member_Count,
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public String Name { get; set; } = String.Empty;
|
|
public Sax.OrganisationType OrganisationType { get; set; }
|
|
public Sax.OrganisationCategory OrganisationCategory { get; set; }
|
|
public String PhoneMain { get; set; } = String.Empty;
|
|
public String PhoneAlt { get; set; } = String.Empty;
|
|
public SysId SportIdPrimary { get; set; }
|
|
public SysId RegionIdPrimary { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { CheckChanged(data.Name, value); data.Name = value; }
|
|
}
|
|
public Sax.OrganisationType OrganisationType
|
|
{
|
|
get { return data.OrganisationType; }
|
|
set { CheckChangedEnum(data.OrganisationType, value); data.OrganisationType = value; }
|
|
}
|
|
public Sax.OrganisationCategory OrganisationCategory
|
|
{
|
|
get { return data.OrganisationCategory; }
|
|
set { CheckChangedEnum(data.OrganisationCategory, value); data.OrganisationCategory = value; }
|
|
}
|
|
public String PhoneMain
|
|
{
|
|
get { return data.PhoneMain; }
|
|
set { CheckChanged(data.PhoneMain, value); data.PhoneMain = value; }
|
|
}
|
|
public String PhoneAlt
|
|
{
|
|
get { return data.PhoneAlt; }
|
|
set { CheckChanged(data.PhoneAlt, value); data.PhoneAlt = value; }
|
|
}
|
|
public SysId SportIdPrimary
|
|
{
|
|
get { return data.SportIdPrimary; }
|
|
set { CheckChanged(data.SportIdPrimary, value); data.SportIdPrimary = value; }
|
|
}
|
|
public SysId RegionIdPrimary
|
|
{
|
|
get { return data.RegionIdPrimary; }
|
|
set { CheckChanged(data.RegionIdPrimary, value); data.RegionIdPrimary = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
Name = data.Name;
|
|
OrganisationType = data.OrganisationType;
|
|
OrganisationCategory = data.OrganisationCategory;
|
|
PhoneMain = data.PhoneMain;
|
|
PhoneAlt = data.PhoneAlt;
|
|
SportIdPrimary = data.SportIdPrimary;
|
|
RegionIdPrimary = data.RegionIdPrimary;
|
|
base.PopulateFrom(data);
|
|
}
|
|
public Data Clone()
|
|
{
|
|
Data data = new Data();
|
|
data.PopulateFrom(this);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Error field - identify properties with validation error.
|
|
public new class ErrField : SacsHierarchyItem.ErrField
|
|
{
|
|
// Identifies the field that has invalid data.
|
|
public ValidValue Name { get; set; } = ValidValue.Valid;
|
|
public ValidValue OrganisationType { get; set; } = ValidValue.Valid;
|
|
public ValidValue OrganisationCategory { get; set; } = ValidValue.Valid;
|
|
public ValidValue PhoneMain { get; set; } = ValidValue.Valid;
|
|
public ValidValue PhoneAlt { get; set; } = ValidValue.Valid;
|
|
public ValidValue SportIdPrimary { get; set; } = ValidValue.Valid;
|
|
public ValidValue RegionIdPrimary { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaxOrganisation(SysId id) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status.
|
|
private static readonly List<SaStatus> validStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Awaiting,
|
|
SaStatus.Active,
|
|
SaStatus.OnHold,
|
|
SaStatus.Inactive,
|
|
SaStatus.Deleted,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Active; } }
|
|
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(validStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
if (status == SaStatus.Active) return DataValue.TriStateType.Green;
|
|
if (status == SaStatus.OnHold) return DataValue.TriStateType.Amber;
|
|
if (status == SaStatus.Inactive) return DataValue.TriStateType.Red;
|
|
if (status == SaStatus.Deleted) return DataValue.TriStateType.Purple;
|
|
return DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
public ItemId GetItemId()
|
|
{
|
|
return new ItemId((short)Sax.DataItemType.Organisation, Id);
|
|
}
|
|
// Sport is mandatory for certain organisation categories.
|
|
public static bool IsSportMandatory(Sax.OrganisationCategory organisationCategory)
|
|
{
|
|
if (organisationCategory == Sax.OrganisationCategory.Club) return true;
|
|
if (organisationCategory == Sax.OrganisationCategory.Association) return true;
|
|
if (organisationCategory == Sax.OrganisationCategory.Education) return true;
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public Data GetData() { return data.Clone(); }
|
|
public void SetData(Data data)
|
|
{
|
|
String fn = GetType().Name + ".SetData";
|
|
// Properties that cannot be changed if previously specified.
|
|
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
|
|
throw new NotSupportedException(fn + " Id cannot be changed");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { data.Name = value; }
|
|
}
|
|
public Sax.OrganisationType OrganisationType
|
|
{
|
|
get { return data.OrganisationType; }
|
|
set { data.OrganisationType = value; }
|
|
}
|
|
public Sax.OrganisationCategory OrganisationCategory
|
|
{
|
|
get { return data.OrganisationCategory; }
|
|
set { data.OrganisationCategory = value; }
|
|
}
|
|
public String PhoneMain
|
|
{
|
|
get { return data.PhoneMain; }
|
|
set { data.PhoneMain = value; }
|
|
}
|
|
public String PhoneAlt
|
|
{
|
|
get { return data.PhoneAlt; }
|
|
set { data.PhoneAlt = value; }
|
|
}
|
|
public SysId SportIdPrimary
|
|
{
|
|
get { return data.SportIdPrimary; }
|
|
set { data.SportIdPrimary = value; }
|
|
}
|
|
public SysId RegionIdPrimary
|
|
{
|
|
get { return data.RegionIdPrimary; }
|
|
set { data.RegionIdPrimary = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags - positions 1-16 available.
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
// P a r a m s
|
|
//-------------------------------------------------------------------
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
AwaitingOnly,
|
|
ActiveOnly,
|
|
InactiveOnly,
|
|
NotDeleted,
|
|
DeletedOnly,
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
// List filtering.
|
|
public List<SysId> IdsIncluded { get; } = new List<SysId>();
|
|
public List<SysId> IdsExcluded { get; } = new List<SysId>();
|
|
public String NameFull { get; set; }
|
|
public String NamePartial { get; set; }
|
|
public Sax.OrganisationCategory OrganisationCategory { get; set; } = Sax.OrganisationCategory.Unknown;
|
|
public List<Sax.OrganisationCategory> OrganisationCategoriesExcluded { get; } = new List<Sax.OrganisationCategory>();
|
|
public Sax.OrganisationType OrganisationType { get; set; } = Sax.OrganisationType.Unknown;
|
|
/// <summary>Partial match on a number of fields, including name, sport, address, etc.</summary>
|
|
public String OrganisationFilter { get; set; }
|
|
public List<SysId> SportIdsIncluded { get; } = new List<SysId>();
|
|
public List<SysId> RegionIdsIncluded { get; } = new List<SysId>();
|
|
// Common properties.
|
|
public String NotesPartial { get; set; }
|
|
public StatusCat StatusCat { get; set; } = StatusCat.ActiveOnly;
|
|
// Table aliases - blank if not linked.
|
|
public String Alias_Sport_Primary { get; set; }
|
|
public String Alias_Region_Primary { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// Item list extension methods.
|
|
public static class SaxOrganisationList
|
|
{
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Extract the Organisation Ids.
|
|
/// </summary>
|
|
public static List<SysId>GetIds(this List<SaxOrganisation> values)
|
|
{
|
|
return values.Select(item => item.Id).ToList();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Extract the first Organisation in list with the specified Id.
|
|
/// </summary>
|
|
public static SaxOrganisation GetOrganisationById(this List<SaxOrganisation> values, SysId organisationId)
|
|
{
|
|
return values.Find(item => item.Id.Equals(organisationId));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|