Move Saxonite’s projects into a dedicated `Workspace` folder and align the solution with .NET 10 and the current Common workspace. Update encryption integration, test project structure and coverage, and repository guidance and upgrade notes. - Relocate application and library projects while retaining Git rename history. - Split tests into Admin, Online, and Shared projects; add representative behavioral and serialization tests. - Update Common integration, application version, and repository documentation. Application version: 1.3.0 Reviewed-on: #1 Co-authored-by: andy <andy@sarand.com>
324 lines
10 KiB
C#
324 lines
10 KiB
C#
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.Standard.Base.App;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using static Saxonite.Net.Standard.Base.App.Sax.Config.Security;
|
|
|
|
namespace Saxonite.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
// User Eligibility.
|
|
//=======================================================================
|
|
public abstract class SaxUserEligibility : SaxDisposableHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
// User.
|
|
UserAccountId,
|
|
User_EmailAddress,
|
|
User_DisplayName,
|
|
User_Title,
|
|
User_FirstName,
|
|
User_LastName,
|
|
// Region.
|
|
RegionId,
|
|
Region_Type,
|
|
Region_Type_Desc,
|
|
Region_CountryIso2Code,
|
|
Region_Name,
|
|
Region_ParentId,
|
|
// Eligibility.
|
|
EligibilityType,
|
|
EligibilityType_Desc,
|
|
Info,
|
|
ExpiresOn,
|
|
// Associated data.
|
|
// Common.
|
|
Notes,
|
|
Flags,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId UserAccountId { get; set; }
|
|
public SysId RegionId { get; set; }
|
|
public String Info { get; set; }
|
|
public Sax.EligibilityType EligibilityType { get; set; }
|
|
public DateTime? ExpiresOn { get; set; } = null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public SysId UserAccountId
|
|
{
|
|
get { return data.UserAccountId; }
|
|
set { CheckChanged(data.UserAccountId, value); data.UserAccountId = value; }
|
|
}
|
|
public SysId RegionId
|
|
{
|
|
get { return data.RegionId; }
|
|
set { CheckChanged(data.RegionId, value); data.RegionId = value; }
|
|
}
|
|
public Sax.EligibilityType EligibilityType
|
|
{
|
|
get { return data.EligibilityType; }
|
|
set { CheckChanged((int)data.EligibilityType, (int)value); data.EligibilityType = value; }
|
|
}
|
|
public String Info
|
|
{
|
|
get { return data.Info; }
|
|
set { CheckChanged(data.Info, value); data.Info = value; }
|
|
}
|
|
public DateTime? ExpiresOn
|
|
{
|
|
get { return data.ExpiresOn; }
|
|
set { CheckChangedNullable(data.ExpiresOn, value); data.ExpiresOn = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
UserAccountId = data.UserAccountId;
|
|
RegionId = data.RegionId;
|
|
EligibilityType = data.EligibilityType;
|
|
Info = data.Info;
|
|
ExpiresOn = data.ExpiresOn;
|
|
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 UserAccountId { get; set; } = ValidValue.Valid;
|
|
public ValidValue RegionId { get; set; } = ValidValue.Valid;
|
|
public ValidValue EligibilityType { get; set; } = ValidValue.Valid;
|
|
public ValidValue Info { get; set; } = ValidValue.Valid;
|
|
public ValidValue ExpiresOn { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SaxUserEligibility(SysId id, SysId userAccountId, SysId regionId, Sax.EligibilityType eligibilityType) : base(id)
|
|
{
|
|
base.SetData(data);
|
|
UserAccountId = userAccountId;
|
|
RegionId = regionId;
|
|
EligibilityType = eligibilityType;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status.
|
|
private static readonly List<SaStatus> validStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Active,
|
|
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.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.UserEligibility, Id);
|
|
}
|
|
|
|
/// <summary>Maximum number of instances per user, regardless of region.</summary>
|
|
public static int GetMaxInstances(Sax.EligibilityType eligibilityType)
|
|
{
|
|
switch (eligibilityType)
|
|
{
|
|
case Sax.EligibilityType.Birth: return 1;
|
|
case Sax.EligibilityType.Naturalised: return 1;
|
|
case Sax.EligibilityType.Parent: return 2;
|
|
case Sax.EligibilityType.Grandparent: return 4;
|
|
case Sax.EligibilityType.Passport: return 9;
|
|
case Sax.EligibilityType.Visa: return 9;
|
|
}
|
|
return 9;
|
|
}
|
|
|
|
/// <summary>Does the eligibility allow a date range.</summary>
|
|
public static bool AllowsApplicablePeriod(Sax.EligibilityType eligibilityType)
|
|
{
|
|
switch (eligibilityType)
|
|
{
|
|
//case Sax.EligibilityType.Birth:
|
|
//case Sax.EligibilityType.Naturalised:
|
|
//case Sax.EligibilityType.Parent:
|
|
//case Sax.EligibilityType.Grandparent:
|
|
case Sax.EligibilityType.Passport:
|
|
case Sax.EligibilityType.Visa:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public Data GetData() { return data.Clone(); }
|
|
public void SetData(Data data)
|
|
{
|
|
// Properties that cannot be changed if previously specified.
|
|
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Id cannot be changed");
|
|
if (SysId.IsValid(UserAccountId) && SysId.ToInt(UserAccountId) != SysId.ToInt(data.UserAccountId))
|
|
throw new NotSupportedException($"{SysUtil.Fn} User Account Id cannot be changed");
|
|
if (SysId.IsValid(RegionId) && SysId.ToInt(RegionId) != SysId.ToInt(data.RegionId))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Region Id cannot be changed");
|
|
if (EligibilityType == 0 && (int)EligibilityType != (int)EligibilityType)
|
|
throw new NotSupportedException($"{SysUtil.Fn} User Eligibility cannot be changed");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
|
|
/// <summary>User Account Id. NB Can only be set where previously invalid.</summary>
|
|
public SysId UserAccountId
|
|
{
|
|
get { return data.UserAccountId; }
|
|
protected set
|
|
{
|
|
if (SysId.IsValid(UserAccountId) && SysId.ToInt(UserAccountId) != SysId.ToInt(data.UserAccountId))
|
|
throw new NotSupportedException("EligibilityType.UserAccountId cannot be changed");
|
|
data.UserAccountId = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Region Id. NB Can only be set where previously invalid.</summary>
|
|
public SysId RegionId
|
|
{
|
|
get { return data.RegionId; }
|
|
set
|
|
{
|
|
if (SysId.IsValid(RegionId) && SysId.ToInt(RegionId) != SysId.ToInt(data.RegionId))
|
|
throw new NotSupportedException("EligibilityType.RegionId cannot be changed");
|
|
data.RegionId = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>User Eligibility. Can only be populated on construction.</summary>
|
|
public Sax.EligibilityType EligibilityType
|
|
{
|
|
get { return data.EligibilityType; }
|
|
set { data.EligibilityType = value; }
|
|
}
|
|
|
|
public String Info
|
|
{
|
|
get { return data.Info; }
|
|
set { data.Info = value; }
|
|
}
|
|
|
|
public DateTime? ExpiresOn
|
|
{
|
|
get { return data.ExpiresOn; }
|
|
set { data.ExpiresOn = 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,
|
|
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 List<SysId> UserAccountIdsIncluded { get; } = new List<SysId>();
|
|
public List<SysId> RegionIdsIncluded { get; } = new List<SysId>();
|
|
public List<Sax.EligibilityType> EligibilityTypesIncluded { get; } = new List<Sax.EligibilityType>();
|
|
public DateTime ValidOn { get; set; }
|
|
// Common properties.
|
|
public String NotesPartial { get; set; }
|
|
public StatusCat StatusCat { get; set; } = StatusCat.NotDeleted;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// Item list extension methods.
|
|
public static class SaxEligibilityTypeList
|
|
{
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Retrieve the first entry in the list matching the specified Region.</summary>
|
|
public static List<SaxUserEligibility> GetEligibilityTypesByStatus(this List<SaxUserEligibility> values, SysId regionId)
|
|
{
|
|
return values.FindAll(item => item.RegionId == regionId);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Retrieve the first entry in the list matching the specified Eligibility.</summary>
|
|
public static SaxUserEligibility GetEligibilityTypeByEligibility(this List<SaxUserEligibility> values, Sax.EligibilityType EligibilityType)
|
|
{
|
|
return values.Find(item => item.EligibilityType == EligibilityType);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|