188 lines
10 KiB
C#
188 lines
10 KiB
C#
using Sarand.BusinessMgr.Net.Core.Web.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
|
|
using Sarand.BusinessMgr.Web.Control.Components;
|
|
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 System;
|
|
|
|
namespace Sarand.BusinessMgr.Web.Control.Models.Account
|
|
{
|
|
//=======================================================================
|
|
public class Model_UserAccount : SbmModel_Control
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_UserAccount(SbmLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Filter properties.
|
|
public class FilterData
|
|
{
|
|
public string Search { get; set; }
|
|
public string EmailAddress { get; set; }
|
|
public string StatusCat { get; set; }
|
|
public SbmcUserAccount.StatusCat GetStatusCat()
|
|
{
|
|
return EnumUtil.ParseEnum(StatusCat, SbmcUserAccount.StatusCat.NotDeleted);
|
|
}
|
|
}
|
|
public FilterData Filter { get; } = new FilterData();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item properties.
|
|
public class UserAccountData
|
|
{
|
|
public String Exists { get; set; }
|
|
public string Id { get; set; }
|
|
public string EmailAddress { get; set; }
|
|
public string Title { get; set; }
|
|
public string FirstName { get; set; }
|
|
public string Initials { get; set; }
|
|
public string LastName { get; set; }
|
|
public string PhoneMain { get; set; }
|
|
public string PhoneMobile { get; set; }
|
|
public string PhoneAlt { get; set; }
|
|
public string StatusCode { get; set; }
|
|
public SaStatus GetStatus() { return SacsSystem.GetStatusForCode(StatusCode); }
|
|
}
|
|
public UserAccountData User { get; } = new UserAccountData();
|
|
// User emails.
|
|
public string UserEmailAcountActivationPortal { get; set; }
|
|
public string UserEmailRequestPasswordPortal { get; set; }
|
|
public string UserEmailRequestPasswordControl { get; set; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// User.
|
|
public bool ValidateUserData(Sacs.Web.Components.SaController.AjaxResponse_Data responseData)
|
|
{
|
|
// Record disposable items as they are created so all can be disposed when needed.
|
|
using (DisposableCollection<ISacsDisposable> disposables = new DisposableCollection<ISacsDisposable>())
|
|
{
|
|
|
|
// User email.
|
|
if (User.EmailAddress != null)
|
|
{
|
|
string controlName = "UserEmailAddress";
|
|
User.EmailAddress = User.EmailAddress.ToLowerInvariant();
|
|
responseData.SetControlValue(controlName, User.EmailAddress);
|
|
if (User.EmailAddress.IsBlank())
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(User.EmailAddress) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_EmailAddress))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_EmailAddress)]);
|
|
else if (!SacsDataValidationHelper.IsValidEmailAddress(User.EmailAddress))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
else
|
|
{
|
|
// Check for duplicate email address.
|
|
SbmcUserAccount.Params prmUserAccount = new SbmcUserAccount.Params();
|
|
SysId userAccountId = SysId.ToSysId(User.Id);
|
|
if (SysId.IsValid(userAccountId))
|
|
prmUserAccount.IdsExcluded.Add(userAccountId);
|
|
prmUserAccount.EmailAddress = User.EmailAddress;
|
|
prmUserAccount.StatusCat = SbmcUserAccount.StatusCat.Any;
|
|
if (ControlAccountMgr.GetUserAccountCount(prmUserAccount) > 0)
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.duplicate.value"]);
|
|
}
|
|
}
|
|
|
|
// User title.
|
|
if (User.Title != null)
|
|
{
|
|
string controlName = "UserTitle";
|
|
responseData.SetControlValue(controlName, User.Title);
|
|
if (StringUtil.GetLength(User.Title) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Title))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Title)]);
|
|
}
|
|
|
|
// User first name.
|
|
if (User.FirstName != null)
|
|
{
|
|
string controlName = "UserFirstName";
|
|
responseData.SetControlValue(controlName, User.FirstName);
|
|
if (User.FirstName.IsBlank())
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(User.FirstName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_FirstName))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_FirstName)]);
|
|
}
|
|
|
|
// User title.
|
|
if (User.Initials != null)
|
|
{
|
|
string controlName = "UserInitials";
|
|
responseData.SetControlValue(controlName, User.Initials);
|
|
if (StringUtil.GetLength(User.Initials) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Initials))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_Initials)]);
|
|
}
|
|
|
|
// User last name.
|
|
if (User.LastName != null)
|
|
{
|
|
string controlName = "UserLastName";
|
|
responseData.SetControlValue(controlName, User.LastName);
|
|
if (User.LastName.IsBlank())
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(User.LastName) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_LastName))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_LastName)]);
|
|
}
|
|
|
|
// Phone.
|
|
if (User.PhoneMain != null)
|
|
{
|
|
string controlName = "UserPhoneMain";
|
|
responseData.SetControlValue(controlName, User.PhoneMain);
|
|
if (StringUtil.GetLength(User.PhoneMain) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMain))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMain)]);
|
|
else if (!User.PhoneMain.IsEmpty() && !SacsDataValidationHelper.IsValidPhone(User.PhoneMain))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// Mobile Phone.
|
|
if (User.PhoneMobile != null)
|
|
{
|
|
string controlName = "UserPhoneMobile";
|
|
responseData.SetControlValue(controlName, User.PhoneMobile);
|
|
if (StringUtil.GetLength(User.PhoneMobile) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMobile))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMobile)]);
|
|
else if (!User.PhoneMobile.IsEmpty() && !SacsDataValidationHelper.IsValidPhone(User.PhoneMobile))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// Alt Phone.
|
|
if (User.PhoneAlt != null)
|
|
{
|
|
string controlName = "UserPhoneAlt";
|
|
responseData.SetControlValue(controlName, User.PhoneAlt);
|
|
if (StringUtil.GetLength(User.PhoneAlt) > GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneAlt))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneAlt)]);
|
|
else if (!User.PhoneAlt.IsEmpty() && !SacsDataValidationHelper.IsValidPhone(User.PhoneAlt))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// User status.
|
|
if (User.StatusCode != null)
|
|
{
|
|
string controlName = "UserStatus";
|
|
if (User.StatusCode.IsBlank())
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!SbmcUserAccount.ValidStatuses.Contains(User.GetStatus()))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|