277 lines
12 KiB
C#
277 lines
12 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Sarand.Net.Standard.Base.App;
|
|
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 Saxonite.Net.Standard.Base.Helpers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using static Saxonite.Net.Standard.Base.App.Sax;
|
|
using static Saxonite.Net.Standard.Base.Bus.SaxArticle;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Models
|
|
{
|
|
//=======================================================================
|
|
public class Model_Account : SaxModel_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_Account(SaxLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
// Model data.
|
|
Organisation = new ModelData_Organisation(this);
|
|
|
|
// Page includes.
|
|
AdditionalFiles_CSS.Add("css/sax-account.css");
|
|
AdditionalFiles_JS.Add("js/sax-account.js");
|
|
AdditionalFiles_JS.Add("js/sax-pro-usr.js");
|
|
AdditionalFiles_JS.Add("js/sax-pro-cfg.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 AccountAbout { 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 ProfileSportParticipatingCode { get; set; }
|
|
public Sax.SportParticipating ProfileSportParticipating
|
|
{
|
|
get { return (Sax.SportParticipating)SportParticipatingCodes.GetTypeForCode(ProfileSportParticipatingCode); }
|
|
set { ProfileSportParticipatingCode = SportParticipatingCodes.GetCodeForType(value); }
|
|
}
|
|
public String ProfileSportPreparingCode { get; set; }
|
|
public Sax.SportPreparing ProfileSportPreparing
|
|
{
|
|
get { return (Sax.SportPreparing)SportPreparingCodes.GetTypeForCode(ProfileSportPreparingCode); }
|
|
set { ProfileSportPreparingCode = SportPreparingCodes.GetCodeForType(value); }
|
|
}
|
|
public String ProfileSportOfficiatingCode { get; set; }
|
|
public Sax.SportOfficiating ProfileSportOfficiating
|
|
{
|
|
get { return (Sax.SportOfficiating)SportOfficiatingCodes.GetTypeForCode(ProfileSportOfficiatingCode); }
|
|
set { ProfileSportOfficiatingCode = SportOfficiatingCodes.GetCodeForType(value); }
|
|
}
|
|
public String ProfileSportAbout { get; set; }
|
|
public class SportsContactsData
|
|
{
|
|
// Contacts.
|
|
/// <summary>Placeholder field value to indicate the number of Contacts in form (even if none are populated).</summary>
|
|
public String Count { get; set; }
|
|
public String[] ContactType { get; set; }
|
|
public String[] UserAccountId { get; set; }
|
|
public String[] Title { get; set; }
|
|
public String[] FirstName { get; set; }
|
|
public String[] LastName { get; set; }
|
|
public String[] EmailAddress { get; set; }
|
|
public String[] Phone { get; set; }
|
|
/// <summary>Sport Contacts to be populated during validation.</summary>
|
|
public SaxSportContactsData ContactsData { get; set; }
|
|
}
|
|
public SportsContactsData Contacts {get; } = new SportsContactsData();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Organisation properties.
|
|
public ModelData_Organisation Organisation { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate model data.
|
|
//-------------------------------------------------------------------
|
|
// Validate 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)]);
|
|
}
|
|
|
|
// About.
|
|
if (AccountAbout != null)
|
|
{
|
|
responseData.SetControlValue(nameof(AccountAbout), AccountAbout);
|
|
if (!StringUtil.IsEmpty(AccountAbout))
|
|
{
|
|
if (StringUtil.GetLength(AccountAbout) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_About))
|
|
responseData.SetControlError(nameof(AccountAbout), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_About)]);
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
// 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.
|
|
SysId regionIdCountry = ExtractSysId(AccountRegionIdCountry);
|
|
if (AccountRegionIdCountry != null && SysId.IsValid(regionIdCountry))
|
|
{
|
|
SaxRegion.Data regionCountry = Internals.GetRegion(regionIdCountry);
|
|
if (regionCountry == null)
|
|
responseData.SetControlError(nameof(AccountRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// Province Region.
|
|
if (AccountRegionIdProvince != null)
|
|
{
|
|
SysId regionIdProvince = ExtractSysId(AccountRegionIdProvince);
|
|
SaxRegion.Data regionProvince = Internals.GetRegion(regionIdProvince);
|
|
if (regionProvince == null)
|
|
responseData.SetControlError(nameof(AccountRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate Sport data.
|
|
public bool ValidateProfileSportData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
String fn = GetType().Name + ".ValidateProfileSportData";
|
|
|
|
// Sport.
|
|
if (ProfileSportId != null)
|
|
{
|
|
SysId profileSportId = ExtractSysId(ProfileSportId);
|
|
if (!SysId.IsValid(profileSportId))
|
|
responseData.SetControlError(nameof(ProfileSportId), Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// About.
|
|
if (ProfileSportAbout != null)
|
|
{
|
|
responseData.SetControlValue(nameof(ProfileSportAbout), ProfileSportAbout);
|
|
if (!StringUtil.IsEmpty(ProfileSportAbout))
|
|
{
|
|
if (StringUtil.GetLength(ProfileSportAbout) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserSport_About))
|
|
responseData.SetControlError(nameof(ProfileSportAbout), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserSport_About)]);
|
|
}
|
|
}
|
|
|
|
// Sport Contacts.
|
|
if (Contacts != null)
|
|
{
|
|
Contacts.ContactsData = new SaxSportContactsData("");
|
|
Contacts.ContactType= Contacts.ContactType ?? new String[0];
|
|
Contacts.Title= Contacts.Title ?? new String[0];
|
|
Contacts.FirstName = Contacts.FirstName ?? new String[0];
|
|
Contacts.LastName = Contacts.LastName ?? new String[0];
|
|
Contacts.EmailAddress = Contacts.EmailAddress ?? new String[0];
|
|
for (int idx = 0; idx < Contacts.ContactType.Length; idx++)
|
|
{
|
|
String contactTypeValue = Contacts.ContactType[idx];
|
|
String title = idx < Contacts.Title.Length ? Contacts.Title[idx] : null;
|
|
String firstName = idx < Contacts.FirstName.Length ? Contacts.FirstName[idx] : null;
|
|
String lastName = idx < Contacts.LastName.Length ? Contacts.LastName[idx] : null;
|
|
String emailAddress = idx < Contacts.EmailAddress.Length ? Contacts.EmailAddress[idx] : null;
|
|
String phone = idx < Contacts.Phone.Length ? Contacts.Phone[idx] : null;
|
|
if (StringUtil.IsBlank(contactTypeValue) && StringUtil.IsBlank(lastName)) continue;
|
|
Sax.SportContactType contactType= (Sax.SportContactType)SportContactTypeCodes.GetTypeForCode(contactTypeValue);
|
|
if (contactType > 0)
|
|
{
|
|
Contacts.ContactsData.SetContactName(contactType, title, firstName, lastName);
|
|
Contacts.ContactsData.SetContactEmailAddress(contactType, emailAddress);
|
|
Contacts.ContactsData.SetContactPhone(contactType, phone);
|
|
}
|
|
else SaLogger.Warn(fn + " Invalid Sport Contact data. Type: " + contactTypeValue + ". Last name: " + lastName);
|
|
}
|
|
if (Contacts.ContactsData.ContactTypes.Count != Contacts.Count.ToInt())
|
|
{
|
|
SaLogger.Warn(fn + " Inconsistent Contact Methods received. Expected: " + Contacts.Count + ". Received: " + Contacts.ContactsData.ContactTypes.Count);
|
|
responseData.SetMessage("caption.contact.method", "System error");
|
|
}
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate Organisation data.
|
|
public bool ValidateProfileOrganisationData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
Organisation.ValidateOrganisationData(responseData);
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|