151 lines
6.1 KiB
C#
151 lines
6.1 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.Admin.Models
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Address model data properties.
|
|
/// </summary>
|
|
public class ModelData_Address : ModelData_Admin
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public ModelData_Address(SaxModel_Admin model, String controlNameSuffix) : base(model)
|
|
{
|
|
this.ControlNameSuffix = StringUtil.EmptyOnNull(controlNameSuffix) + "Address";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
private String ControlNameSuffix { get; }
|
|
// Address properties.
|
|
public String Id { get; set; }
|
|
public String Line1 { get; set; }
|
|
public String Line2 { get; set; }
|
|
public String Line3 { get; set; }
|
|
public String Town { get; set; }
|
|
public String Province { get; set; }
|
|
public String RegionIdProvince { get; set; }
|
|
public String Country { get; set; }
|
|
public String PostalCode { get; set; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
/// <summary>Have any address values been supplied by the form.</summary>
|
|
public bool IsSpecified()
|
|
{
|
|
if (Id != null || Line1 != null || Town != null || Province != null || Country != null || PostalCode != null)
|
|
return true;
|
|
return false;
|
|
}
|
|
/// <summary>Have any address values been populated on the form.</summary>
|
|
public bool IsPopulated()
|
|
{
|
|
if (SysId.IsValid(Id.ToSysId()) || !StringUtil.IsEmpty(Line1) || !StringUtil.IsEmpty(Town) || !StringUtil.IsEmpty(Province) || !StringUtil.IsEmpty(Country) || !StringUtil.IsEmpty(PostalCode))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// Address.
|
|
public bool ValidateAddressData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// Are any properties populated.
|
|
bool populated = IsPopulated();
|
|
|
|
// Address Line 1 - optional.
|
|
if (Line1 != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "Line1", Line1);
|
|
if (StringUtil.GetLength(Line1) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line1))
|
|
responseData.SetControlError(ControlNameSuffix + "Line1", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line1)]);
|
|
}
|
|
|
|
// Address Line 2 - optional.
|
|
if (Line2 != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "Line2", Line2);
|
|
if (!StringUtil.IsEmpty(Line2))
|
|
{
|
|
if (StringUtil.GetLength(Line2) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line2))
|
|
responseData.SetControlError(ControlNameSuffix + "Line2", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line2)]);
|
|
}
|
|
}
|
|
|
|
// Address Line 3 - optional.
|
|
if (Line3 != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "Line3", Line3);
|
|
if (!StringUtil.IsEmpty(Line3))
|
|
{
|
|
if (StringUtil.GetLength(Line3) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line3))
|
|
responseData.SetControlError(ControlNameSuffix + "Line3", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Line3)]);
|
|
}
|
|
}
|
|
|
|
// Address Town - mandatory if any value populated.
|
|
if (Town != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "Town", Town);
|
|
if (StringUtil.IsEmpty(Town) && populated)
|
|
responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(Town) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town))
|
|
responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)]);
|
|
}
|
|
|
|
// Address Province - optional.
|
|
if (Province != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "Province", Province);
|
|
if (!StringUtil.IsEmpty(Province))
|
|
{
|
|
if (StringUtil.GetLength(Province) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province))
|
|
responseData.SetControlError(ControlNameSuffix + "Province", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Province)]);
|
|
}
|
|
}
|
|
|
|
// Address Country - optional.
|
|
if (Country != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "Country", Country);
|
|
if (!StringUtil.IsEmpty(Country))
|
|
{
|
|
if (StringUtil.GetLength(Country) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Country))
|
|
responseData.SetControlError(ControlNameSuffix + "Country", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Country)]);
|
|
}
|
|
}
|
|
|
|
// Address PostalCode - optional.
|
|
if (PostalCode != null)
|
|
{
|
|
responseData.SetControlValue(ControlNameSuffix + "PostalCode", PostalCode);
|
|
if (!StringUtil.IsEmpty(PostalCode))
|
|
{
|
|
if (StringUtil.GetLength(PostalCode) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_PostalCode))
|
|
responseData.SetControlError(ControlNameSuffix + "PostalCode", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_PostalCode)]);
|
|
}
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|