167 lines
7.1 KiB
C#
167 lines
7.1 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
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.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Core.Web.Base.Models;
|
|
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
|
|
{
|
|
//=======================================================================
|
|
public class Model_Account : SaxModel_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_Account(SaxLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
AdditionalFiles_CSS.Add("css/sax-account.css");
|
|
AdditionalFiles_JS.Add("js/sax-account.js");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Contact Properties.
|
|
public String AccountEmailAddress { get; set; }
|
|
public String AccountTitle { get; set; }
|
|
public String AccountFirstName { get; set; }
|
|
public String AccountLastName { get; set; }
|
|
public String AccountGender { get; set; }
|
|
public Sax.Gender GetAccountGender()
|
|
{
|
|
return (Sax.Gender)StringUtil.ToShort(AccountGender);
|
|
}
|
|
public String AccountDobDay { get; set; }
|
|
public String AccountDobMonth{ get; set; }
|
|
public String AccountDobYear{ get; set; }
|
|
// Regions.
|
|
public String AccountRegionIdCountry { get; set; }
|
|
public String AccountRegionCaptionCountry { get; }
|
|
public String AccountRegionIdProvince { get; set; }
|
|
public String AccountRegionCaptionProvince { get; }
|
|
// Image.
|
|
public List<IFormFile> AccountContactImage { get; set; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Sport properties.
|
|
public String UserSportId { get; set; }
|
|
public String ProfileSportId { get; set; }
|
|
public String ProfileSportExists { get; set; }
|
|
public String ProfileSportParticipationCode { get; set; }
|
|
public Sax.SportParticipation ProfileSportParticipation
|
|
{
|
|
get { return (Sax.SportParticipation)SportParticipationCodes.GetTypeForCode(ProfileSportParticipationCode); }
|
|
set { ProfileSportParticipationCode = SportParticipationCodes.GetCodeForType(value); }
|
|
}
|
|
public String ProfileSportOfficiatingCode { get; set; }
|
|
public Sax.SportOfficiating ProfileSportOfficiating
|
|
{
|
|
get { return (Sax.SportOfficiating)SportOfficiatingCodes.GetTypeForCode(ProfileSportOfficiatingCode); }
|
|
set { ProfileSportOfficiatingCode = SportOfficiatingCodes.GetCodeForType(value); }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate users's contact details.
|
|
public bool ValidateContactDetails(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
//---------------------------------------------------------------
|
|
// Title.
|
|
if (AccountTitle != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountTitle), AccountTitle);
|
|
if (StringUtil.IsEmpty(AccountTitle))
|
|
responseData.SetControlError(nameof(AccountTitle), Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(AccountTitle) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_Title))
|
|
responseData.SetControlError(nameof(AccountTitle), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_Title)]);
|
|
}
|
|
|
|
// First Name.
|
|
if (AccountFirstName != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountFirstName), AccountFirstName);
|
|
if (StringUtil.IsEmpty(AccountFirstName))
|
|
responseData.SetControlError(nameof(AccountFirstName), Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(AccountFirstName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName))
|
|
responseData.SetControlError(nameof(AccountFirstName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName)]);
|
|
}
|
|
|
|
// Last Name.
|
|
if (AccountLastName != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountLastName), AccountLastName);
|
|
if (StringUtil.IsEmpty(AccountLastName))
|
|
responseData.SetControlError(nameof(AccountLastName), Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(AccountLastName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName))
|
|
responseData.SetControlError(nameof(AccountLastName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName)]);
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
// Date of birth.
|
|
if (AccountDobYear != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountDobYear), AccountDobYear);
|
|
short dobYear = StringUtil.ToShort(AccountDobYear);
|
|
if (!StringUtil.IsNumeric(AccountDobYear) || dobYear > DateTime.Today.Year)
|
|
responseData.SetControlError(nameof(AccountDobYear), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
if (AccountDobMonth != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountDobMonth), AccountDobMonth);
|
|
short dobMonth = StringUtil.ToShort(AccountDobMonth);
|
|
if (!StringUtil.IsEmpty(AccountDobMonth) && (!StringUtil.IsNumeric(AccountDobMonth) || dobMonth < 0 || dobMonth > 12))
|
|
responseData.SetControlError(nameof(AccountDobMonth), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
if (AccountDobDay != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountDobDay), AccountDobDay);
|
|
short dobDay = StringUtil.ToShort(AccountDobDay);
|
|
if (!StringUtil.IsEmpty(AccountDobDay) && (!StringUtil.IsNumeric(AccountDobDay) || dobDay < 0 || dobDay > 31))
|
|
responseData.SetControlError(nameof(AccountDobDay), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
// Country Region.
|
|
if (AccountRegionIdCountry != null && SysId.IsValid(AccountRegionIdCountry.ToSysId()))
|
|
{
|
|
SaxRegion regionCountry = Internals.GetRegion(AccountRegionIdCountry.ToSysId());
|
|
if (regionCountry == null)
|
|
responseData.SetControlError(nameof(AccountRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// Province Region.
|
|
if (AccountRegionIdProvince != null)
|
|
{
|
|
SaxRegion regionProvince = Internals.GetRegion(AccountRegionIdProvince.ToSysId());
|
|
if (regionProvince == null)
|
|
responseData.SetControlError(nameof(AccountRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
public bool ValidateProfileSportData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// Sport.
|
|
if (ProfileSportId != null)
|
|
{
|
|
SysId profileSportId = ProfileSportId.ToSysId();
|
|
if (!SysId.IsValid(profileSportId))
|
|
responseData.SetControlError(nameof(ProfileSportId), Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|