133 lines
5.2 KiB
C#
133 lines
5.2 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.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.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Saxonite.Net.Core.Web.Admin.Models
|
|
{
|
|
//=======================================================================
|
|
public class Model_User : SaxModel_Admin
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_User(SaxLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
AdditionalFiles_JS.Add("js/sax-user.js");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// User list configuration.
|
|
public class FilterData
|
|
{
|
|
public String User { get; set; }
|
|
}
|
|
public FilterData Filter { get; } = new FilterData();
|
|
|
|
//-------------------------------------------------------------------
|
|
// User properties.
|
|
public String UserAccountId { get; set; }
|
|
[EmailAddress]
|
|
public String UserEmailAddress { get; set; }
|
|
public String UserTitle { get; set; }
|
|
public String UserFirstName { get; set; }
|
|
public String UserLastName { get; set; }
|
|
public String UserRoleCodeDelim = ",";
|
|
public List<String> UserRoleCodes { get; set; }
|
|
public List<String> GetUserRoleCodes()
|
|
{
|
|
List<String> codes = new List<string>();
|
|
foreach (String code in UserRoleCodes)
|
|
{
|
|
if (StringUtil.IsEmpty(code)) continue;
|
|
codes.AddRange(code.Split(UserRoleCodeDelim));
|
|
}
|
|
return codes;
|
|
}
|
|
public String UserStatusCode { get; set; }
|
|
public SaStatus UserStatus { get { return SacsSystem.GetStatusForCode(UserStatusCode); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// User.
|
|
public bool ValidateUserData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// User email.
|
|
if (UserEmailAddress != null)
|
|
{
|
|
UserEmailAddress = UserEmailAddress.ToLowerInvariant();
|
|
responseData.SetControlValue(nameof(UserEmailAddress), UserEmailAddress);
|
|
if (StringUtil.IsEmpty(UserEmailAddress))
|
|
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(UserEmailAddress) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress))
|
|
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress)]);
|
|
else
|
|
{
|
|
// Check for duplicate email address.
|
|
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
|
SysId userAccountId = UserAccountId.ToSysId();
|
|
if (SysId.IsValid(userAccountId))
|
|
prmUserAccount.IdsExcluded.Add(userAccountId);
|
|
prmUserAccount.EmailAddress = UserEmailAddress;
|
|
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.Any;
|
|
if (AccountMgr.GetUserAccountCount(prmUserAccount) > 0)
|
|
responseData.SetControlError(nameof(UserEmailAddress), Localiser["msg.validation.duplicate.value"]);
|
|
}
|
|
}
|
|
|
|
// User title.
|
|
if (UserTitle != null)
|
|
{
|
|
if (StringUtil.IsEmpty(UserTitle))
|
|
responseData.SetControlError(nameof(UserTitle), Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// User first name.
|
|
if (UserFirstName != null)
|
|
{
|
|
responseData.SetControlValue(nameof(UserFirstName), UserFirstName);
|
|
if (StringUtil.IsEmpty(UserFirstName))
|
|
responseData.SetControlError(nameof(UserFirstName), Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(UserFirstName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName))
|
|
responseData.SetControlError(nameof(UserFirstName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName)]);
|
|
}
|
|
|
|
// User last name.
|
|
if (UserLastName != null)
|
|
{
|
|
responseData.SetControlValue(nameof(UserLastName), UserLastName);
|
|
if (StringUtil.IsEmpty(UserLastName))
|
|
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(UserLastName) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName))
|
|
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName)]);
|
|
}
|
|
|
|
// User status.
|
|
if (UserStatusCode != null)
|
|
{
|
|
if (StringUtil.IsEmpty(UserStatusCode))
|
|
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.mandatory.value"]);
|
|
else if (!SaxUserAccount.ValidStatuses.Contains(UserStatus))
|
|
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|