117 lines
5.4 KiB
C#
117 lines
5.4 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.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
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 PhoneMain { get; set; }
|
|
// Address.
|
|
public ModelData_Address Address { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// Organisation.
|
|
public bool ValidateOrganisationData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
|
|
// 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"]);
|
|
|
|
// 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();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|