157 lines
7.8 KiB
C#
157 lines
7.8 KiB
C#
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Helpers;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using Saxonite.Net.Standard.Base.Helpers;
|
|
using System;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Models
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Organisation model data properties.
|
|
/// </summary>
|
|
public class ModelData_Organisation : ModelData_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public ModelData_Organisation(SaxModel_Online model, String controlNameSuffix = "Organisation") : base(model)
|
|
{
|
|
this.ControlNameSuffix = StringUtil.EmptyOnNull(controlNameSuffix);
|
|
Address = new ModelData_Address(model, ControlNameSuffix);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
private String ControlNameSuffix { get; }
|
|
// Organisation properties.
|
|
public String Id { get; set; }
|
|
public String Name { get; set; }
|
|
public String Type { get; set; }
|
|
public Sax.OrganisationType GetOrganisationType() { return (Sax.OrganisationType)Model.OrganisationTypeCodes.GetTypeForCode(Type); }
|
|
public String Category { get; set; }
|
|
public Sax.OrganisationCategory GetOrganisationCategory() { return (Sax.OrganisationCategory)Model.OrganisationCategoryCodes.GetTypeForCode(Category); }
|
|
public String SportId { get; set; }
|
|
public String RegionIdCountry { get; set; }
|
|
public String About { get; set; }
|
|
public String Facilities { get; set; }
|
|
public String PhoneMain { get; set; }
|
|
// Contact Methods.
|
|
/// <summary>Placeholder field value to indicate the number of Contact Methods in form (even if none are populated).</summary>
|
|
public String ContactMethods { get; set; }
|
|
public String[] ContactMethod { get; set; }
|
|
public String[] ContactValue { get; set; }
|
|
/// <summary>Contact methods to be populated during validation.</summary>
|
|
public SaxContactData ContactData { get; set; }
|
|
// Address.
|
|
public ModelData_Address Address { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// Organisation.
|
|
public bool ValidateOrganisationData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
String fn = this.GetType().Name + ".ValidateOrganisationData";
|
|
|
|
// Name - mandatory.
|
|
responseData.SetControlValue(ControlNameSuffix + "Name", Name);
|
|
if (StringUtil.IsEmpty(Name))
|
|
responseData.SetControlError(ControlNameSuffix + "Name", Model.Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(Name) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Name))
|
|
responseData.SetControlError(ControlNameSuffix + "Name", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Name)]);
|
|
else if (SysId.IsValid(Model.ExtractSysId(RegionIdCountry)))
|
|
{
|
|
// Ensure that the organisation name is unique within the country.
|
|
SaxOrganisation.Params prmOrganisation = new SaxOrganisation.Params();
|
|
if (SysId.IsValid(Model.ExtractSysId(Id)))
|
|
prmOrganisation.IdsExcluded.Add(Model.ExtractSysId(Id));
|
|
prmOrganisation.NameFull = Name;
|
|
prmOrganisation.RegionIdsIncluded.Add(Model.ExtractSysId(RegionIdCountry));
|
|
prmOrganisation.StatusCat = SaxOrganisation.StatusCat.Any;
|
|
if (Model.AccountMgr.GetOrganisationCount(prmOrganisation) > 0)
|
|
responseData.SetControlError(ControlNameSuffix + "Name", Model.Localiser["msg.validation.duplicate.value"]);
|
|
}
|
|
|
|
// Organisation Category - mandatory.
|
|
if (StringUtil.IsEmpty(Category))
|
|
responseData.SetControlError(ControlNameSuffix + "Category", Model.Localiser["msg.validation.mandatory.value"]);
|
|
|
|
// Organisation Type - mandatory.
|
|
if (StringUtil.IsEmpty(Type))
|
|
responseData.SetControlError(ControlNameSuffix + "Type", Model.Localiser["msg.validation.mandatory.value"]);
|
|
|
|
// Sport - mandatory for certain organisation categories.
|
|
if (StringUtil.IsEmpty(SportId) && SaxOrganisation.IsSportMandatory(GetOrganisationCategory()))
|
|
responseData.SetControlError(ControlNameSuffix + "SportId", Model.Localiser["msg.validation.mandatory.value"]);
|
|
else if (!StringUtil.IsEmpty(SportId) && !SysId.IsValid(Model.ExtractSysId(SportId)))
|
|
responseData.SetControlError(ControlNameSuffix + "SportId", Model.Localiser["msg.validation.invalid.value"]);
|
|
|
|
// Region Country - mandatory.
|
|
if (StringUtil.IsEmpty(RegionIdCountry))
|
|
responseData.SetControlError(ControlNameSuffix + "RegionIdCountry", Model.Localiser["msg.validation.mandatory.value"]);
|
|
else if (!SysId.IsValid(Model.ExtractSysId(RegionIdCountry)))
|
|
responseData.SetControlError(ControlNameSuffix + "RegionIdCountry", Model.Localiser["msg.validation.invalid.value"]);
|
|
|
|
// About - optional.
|
|
responseData.SetControlValue(ControlNameSuffix + "About", About);
|
|
if (StringUtil.GetLength(About) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_About))
|
|
responseData.SetControlError(ControlNameSuffix + "About", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_About)]);
|
|
|
|
// Facilities - optional.
|
|
responseData.SetControlValue(ControlNameSuffix + "Facilities", Facilities);
|
|
if (StringUtil.GetLength(Facilities) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Facilities))
|
|
responseData.SetControlError(ControlNameSuffix + "Facilities", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_Facilities)]);
|
|
|
|
// Contact Methods.
|
|
if (ContactMethods != null)
|
|
{
|
|
ContactData = new SaxContactData("");
|
|
ContactMethod = ContactMethod ?? new String[0];
|
|
ContactValue = ContactValue ?? new String[0];
|
|
for (int idx = 0; idx < ContactMethod.Length && idx < ContactValue.Length; idx++)
|
|
{
|
|
String methodValue = ContactMethod[idx];
|
|
String value = ContactValue[idx];
|
|
if (methodValue == null & value == null) continue;
|
|
Sax.ContactMethod method = EnumUtil.ParseEnum(methodValue, Sax.ContactMethod.Unknown);
|
|
if (method > 0 && !value.IsEmpty() && SaxContactMethodHelper.IsValidContactMethodValue(method, value))
|
|
ContactData.SetContactMethodValue(method, value);
|
|
else SaLogger.Warn(fn + " Invalid Contact Method data. Method: " + methodValue + ". Value: " + value);
|
|
}
|
|
if (ContactData.Methods.Count != ContactMethods.ToInt())
|
|
{
|
|
SaLogger.Warn(fn + " Inconsistent Contact Methods received. Expected: " + ContactMethods + ". Received: " + ContactData.Methods.Count);
|
|
responseData.SetMessage("caption.contact.method", "System error");
|
|
}
|
|
}
|
|
|
|
// Phone Main - optional.
|
|
if (PhoneMain != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "PhoneMain", PhoneMain);
|
|
if (!StringUtil.IsEmpty(PhoneMain))
|
|
{
|
|
if (!SacsDataValidationHelper.IsValidPhone(PhoneMain))
|
|
responseData.SetControlError(ControlNameSuffix + "PhoneMain", Model.Localiser["msg.validation.invalid.value"]);
|
|
else if (StringUtil.GetLength(PhoneMain) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_PhoneMain))
|
|
responseData.SetControlError(ControlNameSuffix + "PhoneMain", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.Organisation_PhoneMain)]);
|
|
}
|
|
}
|
|
|
|
// Address.
|
|
Address.ValidateAddressData(responseData);
|
|
|
|
return !responseData.HasControlErrors() && responseData.Message == null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|