|
|
|
@@ -16,6 +16,8 @@ using Sarand.Net.Standard.Base.Core;
|
|
|
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
|
|
|
using Saxonite.Net.Standard.Base.App;
|
|
|
|
|
using Saxonite.Net.Core.Web.Online.Helpers;
|
|
|
|
|
using Org.BouncyCastle.Security;
|
|
|
|
|
using static Saxonite.Net.Standard.Base.App.Sax;
|
|
|
|
|
|
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
|
|
|
{
|
|
|
|
@@ -135,6 +137,35 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
// Account - Get Organisation.
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Associations are grouped by type and direction (parent->child).
|
|
|
|
|
/// <br>The organisation specified in each case is the 'other' organisation (not the current 'target' organisation).</br>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private class AssociationTypeData
|
|
|
|
|
{
|
|
|
|
|
public String Caption { get; set; }
|
|
|
|
|
public List<AssociationOrganisationData> Organisations { get; } = new List<AssociationOrganisationData>();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Association Organisation - the one that is not the current 'target' organisation.
|
|
|
|
|
/// <br>Region and Sport are only populate if different from the 'target' organisation.</br>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private class AssociationOrganisationData
|
|
|
|
|
{
|
|
|
|
|
public String Name { get; set; }
|
|
|
|
|
public String Display
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
String display = Name;
|
|
|
|
|
if (!StringUtil.IsBlank(Sport) || !StringUtil.IsBlank(Region))
|
|
|
|
|
display += " (" + String.Join(", ", new List<String> { Sport, Region }.Where(item => !StringUtil.IsBlank(item))) + ")";
|
|
|
|
|
return display;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public String Region { get; set; }
|
|
|
|
|
public String Sport { get; set; }
|
|
|
|
|
}
|
|
|
|
|
private class OrganisationItemData : OrganisationListData
|
|
|
|
|
{
|
|
|
|
|
public String TypeDesc { get; set; }
|
|
|
|
@@ -143,6 +174,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
|
|
|
public List<AjaxResponse_Data.ItemLabelValue> Contacts { get; set; }
|
|
|
|
|
public String Address { get; set; }
|
|
|
|
|
public String PostalCode { get; set; }
|
|
|
|
|
public List<AssociationTypeData> Associations { get; } = new List<AssociationTypeData>();
|
|
|
|
|
}
|
|
|
|
|
private class AjaxResponse_Search_Organisation : AjaxResponse_Data
|
|
|
|
|
{
|
|
|
|
@@ -228,6 +260,83 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
|
|
|
organisationData.Address = (new List<String>() { addressLines, addressTownProvince }).Concat("\n", "", "", true, true);
|
|
|
|
|
organisationData.PostalCode = address.PostalCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Associations.
|
|
|
|
|
Dictionary<SaxItemAssociation.TypeOptionData, List<AssociationOrganisationData>> associationTypeGroups = new Dictionary<SaxItemAssociation.TypeOptionData, List<AssociationOrganisationData>>();
|
|
|
|
|
ColumnDfn colId = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.Id);
|
|
|
|
|
ColumnDfn colAssociationType = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.AssociationType);
|
|
|
|
|
ColumnDfn colItemTypeFrom = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.ItemTypeFrom);
|
|
|
|
|
ColumnDfn colItemIdFrom = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.ItemIdFrom);
|
|
|
|
|
ColumnDfn colOrganisationFrom_Name = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.OrganisationFrom_Name);
|
|
|
|
|
ColumnDfn colOrganisationFrom_SportIdPrimary = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.OrganisationFrom_SportIdPrimary);
|
|
|
|
|
ColumnDfn colOrganisationFrom_RegionIdPrimary = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.OrganisationFrom_RegionIdPrimary);
|
|
|
|
|
ColumnDfn colItemTypeTo = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.ItemTypeTo);
|
|
|
|
|
ColumnDfn colItemIdTo = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.ItemIdTo);
|
|
|
|
|
ColumnDfn colOrganisationTo_Name = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.OrganisationTo_Name);
|
|
|
|
|
ColumnDfn colOrganisationTo_SportIdPrimary = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.OrganisationTo_SportIdPrimary);
|
|
|
|
|
ColumnDfn colOrganisationTo_RegionIdPrimary = ItemDataMgr.GetItemAssociationColumnDfn(SaxItemAssociation.Column.OrganisationTo_RegionIdPrimary);
|
|
|
|
|
List<ColumnDfn> associationCols = new List<ColumnDfn>()
|
|
|
|
|
{
|
|
|
|
|
colId, colAssociationType,
|
|
|
|
|
colItemTypeFrom, colItemIdFrom, colOrganisationFrom_Name, colOrganisationFrom_SportIdPrimary, colOrganisationFrom_RegionIdPrimary,
|
|
|
|
|
colItemTypeTo, colItemIdTo, colOrganisationTo_Name, colOrganisationTo_SportIdPrimary, colOrganisationTo_RegionIdPrimary
|
|
|
|
|
};
|
|
|
|
|
SaxItemAssociation.Params prmAssociations = new SaxItemAssociation.Params();
|
|
|
|
|
prmAssociations.ItemIdsIncluded.Add(organisation.GetItemId());
|
|
|
|
|
prmAssociations.StatusCat = SaxItemAssociation.StatusCat.ActiveOnly;
|
|
|
|
|
using (DbResultSet resultSet = ItemDataMgr.ExecuteItemAssociationQuery(associationCols, prmAssociations))
|
|
|
|
|
{
|
|
|
|
|
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
|
|
|
|
{
|
|
|
|
|
NamedValue.Map values = resultSet.GetRecordValues();
|
|
|
|
|
SysId associationId = new SysId(values.GetLong(colId.DataName));
|
|
|
|
|
Sax.AssociationType associationType = (Sax.AssociationType)values.GetLong(colAssociationType.DataName);
|
|
|
|
|
ItemId itemIdFrom = new ItemId((short)values.GetLong(colItemTypeFrom.DataName), new SysId(values.GetLong(colItemIdFrom.DataName)));
|
|
|
|
|
ItemId itemIdTo = new ItemId((short)values.GetLong(colItemTypeTo.DataName), new SysId(values.GetLong(colItemIdTo.DataName)));
|
|
|
|
|
bool associationTypeDirectionReversed = associationType == Sax.AssociationType.Affiliate && itemIdTo.Id.Equals(organisation.Id);
|
|
|
|
|
// Determine association type group.
|
|
|
|
|
SaxItemAssociation.TypeOptionData assocTypeOption = new SaxItemAssociation.TypeOptionData(associationType, associationTypeDirectionReversed, GetAssociationTypeOptionCaption(associationType, associationTypeDirectionReversed));
|
|
|
|
|
List<AssociationOrganisationData> organisations = associationTypeGroups.GetValue(assocTypeOption, null);
|
|
|
|
|
if (organisations == null)
|
|
|
|
|
associationTypeGroups.Add(assocTypeOption, organisations = new List<AssociationOrganisationData>());
|
|
|
|
|
// Populate organisation properties.
|
|
|
|
|
SysId orgSportIdFrom = new SysId(values.GetLong(colOrganisationFrom_SportIdPrimary.DataName));
|
|
|
|
|
SysId orgRegionIdFrom = new SysId(values.GetLong(colOrganisationFrom_RegionIdPrimary.DataName));
|
|
|
|
|
SysId orgSportIdTo = new SysId(values.GetLong(colOrganisationTo_SportIdPrimary.DataName));
|
|
|
|
|
SysId orgRegionIdTo = new SysId(values.GetLong(colOrganisationTo_RegionIdPrimary.DataName));
|
|
|
|
|
if (itemIdTo.Id.Equals(organisation.Id))
|
|
|
|
|
{
|
|
|
|
|
// 'From' item is the 'Other' organisation.
|
|
|
|
|
AssociationOrganisationData assocOrgData = new AssociationOrganisationData();
|
|
|
|
|
assocOrgData.Name = values.GetString(colOrganisationFrom_Name.DataName);
|
|
|
|
|
if (!orgSportIdFrom.Equals(orgSportIdTo))
|
|
|
|
|
assocOrgData.Sport = model.GetSportCaption(orgSportIdFrom);
|
|
|
|
|
if (!orgRegionIdFrom.Equals(orgRegionIdTo))
|
|
|
|
|
assocOrgData.Region = model.GetRegionCaption(orgRegionIdFrom);
|
|
|
|
|
organisations.Add(assocOrgData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 'To' item is the 'Other' organisation.
|
|
|
|
|
AssociationOrganisationData assocOrgData = new AssociationOrganisationData();
|
|
|
|
|
assocOrgData.Name = values.GetString(colOrganisationTo_Name.DataName);
|
|
|
|
|
if (!orgSportIdFrom.Equals(orgSportIdTo))
|
|
|
|
|
assocOrgData.Sport = model.GetSportCaption(orgSportIdTo);
|
|
|
|
|
if (!orgRegionIdFrom.Equals(orgRegionIdTo))
|
|
|
|
|
assocOrgData.Region = model.GetRegionCaption(orgRegionIdTo);
|
|
|
|
|
organisations.Add(assocOrgData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Populate associations to response.
|
|
|
|
|
foreach (SaxItemAssociation.TypeOptionData associationTypeGroup in associationTypeGroups.Keys.OrderBy(item => (int)item.TypeOption))
|
|
|
|
|
{
|
|
|
|
|
AssociationTypeData associationTypeData = new AssociationTypeData();
|
|
|
|
|
associationTypeData.Caption = associationTypeGroup.Caption;
|
|
|
|
|
associationTypeData.Organisations.AddRange(associationTypeGroups.GetValue(associationTypeGroup, new List<AssociationOrganisationData>()).OrderBy(item => item.Name).ToList());
|
|
|
|
|
responseData.Organisation.Associations.Add(associationTypeData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Complete response.
|
|
|
|
@@ -235,6 +344,21 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
|
|
|
return Json(responseData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Caption to display above list of corresponding associated organisation for the 'target' organisation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private String GetAssociationTypeOptionCaption(Sax.AssociationType associationType, bool reversed)
|
|
|
|
|
{
|
|
|
|
|
switch (SaxItemAssociation.GetAssociationTypeOption(associationType, reversed))
|
|
|
|
|
{
|
|
|
|
|
case AssociationTypeOption.AffiliateParent: return "Affiliated to";
|
|
|
|
|
case AssociationTypeOption.AffiliateChild: return "Affiliates";
|
|
|
|
|
case AssociationTypeOption.Partner: return "Partners";
|
|
|
|
|
}
|
|
|
|
|
return "Unknown relationship";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
}
|
|
|
|
|
//=======================================================================
|
|
|
|
|