351 lines
12 KiB
C#
351 lines
12 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
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,
|
|
// 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,
|
|
/// <summary>Number of active logo images.</summary>
|
|
LogoImage_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 SysId SportIdPrimary { get; set; }
|
|
public SysId RegionIdPrimary { get; set; }
|
|
public String About { get; set; } = String.Empty;
|
|
public String Facilities { get; set; } = String.Empty;
|
|
public String ContactData { get; set; } = String.Empty;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 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; }
|
|
}
|
|
public String About
|
|
{
|
|
get { return data.About; }
|
|
set { CheckChanged(data.About, value); data.About = value; }
|
|
}
|
|
public String Facilities
|
|
{
|
|
get { return data.Facilities; }
|
|
set { CheckChanged(data.Facilities, value); data.Facilities = value; }
|
|
}
|
|
public String ContactData
|
|
{
|
|
get { return data.ContactData; }
|
|
set { CheckChanged(data.ContactData, value); data.ContactData = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
Name = data.Name;
|
|
OrganisationType = data.OrganisationType;
|
|
OrganisationCategory = data.OrganisationCategory;
|
|
SportIdPrimary = data.SportIdPrimary;
|
|
RegionIdPrimary = data.RegionIdPrimary;
|
|
About = data.About;
|
|
Facilities = data.Facilities;
|
|
ContactData = data.ContactData;
|
|
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 SportIdPrimary { get; set; } = ValidValue.Valid;
|
|
public ValidValue RegionIdPrimary { get; set; } = ValidValue.Valid;
|
|
public ValidValue About { get; set; } = ValidValue.Valid;
|
|
public ValidValue Facilities { get; set; } = ValidValue.Valid;
|
|
public ValidValue ContactData { 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.SportDepartment) return true;
|
|
return false;
|
|
}
|
|
private static List<Sax.ContactMethod> validContactMethods = new List<Sax.ContactMethod>
|
|
{
|
|
Sax.ContactMethod.PhoneMain,
|
|
Sax.ContactMethod.PhoneOffice,
|
|
// Online.
|
|
Sax.ContactMethod.Email,
|
|
Sax.ContactMethod.Website,
|
|
Sax.ContactMethod.Wikipedia,
|
|
// Social media.
|
|
Sax.ContactMethod.LinkedIn,
|
|
Sax.ContactMethod.Twitter,
|
|
Sax.ContactMethod.Facebook,
|
|
Sax.ContactMethod.Instagram,
|
|
};
|
|
public static List<Sax.ContactMethod> ValidContactMethods { get { return new List<Sax.ContactMethod>(validContactMethods); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 SysId SportIdPrimary
|
|
{
|
|
get { return data.SportIdPrimary; }
|
|
set { data.SportIdPrimary = value; }
|
|
}
|
|
public SysId RegionIdPrimary
|
|
{
|
|
get { return data.RegionIdPrimary; }
|
|
set { data.RegionIdPrimary = value; }
|
|
}
|
|
public String About
|
|
{
|
|
get { return data.About; }
|
|
set { data.About = value; }
|
|
}
|
|
public String Facilities
|
|
{
|
|
get { return data.Facilities; }
|
|
set { data.Facilities = value; }
|
|
}
|
|
public String ContactData
|
|
{
|
|
get { return data.ContactData; }
|
|
set { data.ContactData = 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));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Get the name of the first Organisation in list with the specified Id.
|
|
/// </summary>
|
|
public static String GetOrganisationName(this List<SaxOrganisation> values, SysId organisationId)
|
|
{
|
|
return values.Find(item => item.Id.Equals(organisationId))?.Name ?? "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|