Files
BusinessMgr-2019/SaBusinessMgrCoreWebControl/Control/Models/SbmModel_Control.cs
T

72 lines
3.0 KiB
C#

using Microsoft.AspNetCore.Mvc.Rendering;
using Sarand.BusinessMgr.Net.Core.Web.App;
using Sarand.BusinessMgr.Net.Core.Web.Models;
using Sarand.BusinessMgr.Net.Standard.Base.App;
using Sarand.BusinessMgr.Net.Standard.Base.Bus.Control;
using Sarand.BusinessMgr.Net.Standard.Base.Core;
using Sarand.BusinessMgr.Web.Control.App;
using Sarand.Net.Standard.Base.Core;
using System;
using System.Collections.Generic;
namespace Sarand.BusinessMgr.Web.Control.Models
{
//=======================================================================
public class SbmModel_Control : SbmModel_Base
{
//-------------------------------------------------------------------
// Protected construction.
protected SbmModel_Control(SbmLocaliser localiser) :
base(localiser)
{
}
//-------------------------------------------------------------------
// Properties.
protected SbmApplication_Control ControlApp { get { return SbmApplication_Control.Instance; } }
public SbmSessionData_Control SessionData_Control { get { return SessionData as SbmSessionData_Control; } }
public override ISbmUserContext_Core UserContext_Core { get { return new SbmUserContext_Control(SessionData_Control); } }
//-------------------------------------------------------------------
public IEnumerable<SelectListItem> GetInstanceContextsForSelect()
{
List<SelectListItem> items = new List<SelectListItem>();
SbmcRepository.Params prmRepository = new SbmcRepository.Params();
prmRepository.StatusCat = SbmcRepository.StatusCat.NotDeleted;
foreach (SbmcRepository repository in ControlInstanceMgr.GetRepositoryList(prmRepository))
items.Add(new SelectListItem(repository.Context, repository.Context));
return items;
}
//-------------------------------------------------------------------
/// <summary>
/// Form control value max length - BusinessMgr tables.
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
/// </summary>
public int GetControlMaxLength(SbmDbDfn_Control.ColumnIdx column)
{
int maxLength = (int)SbmDbDfn_Control.GetColTextLen(column);
switch (column)
{
case SbmDbDfn_Control.ColumnIdx.UserAccount_EmailAddress:
return Math.Min(maxLength, 100);
case SbmDbDfn_Control.ColumnIdx.UserAccount_FirstName:
case SbmDbDfn_Control.ColumnIdx.UserAccount_LastName:
return Math.Min(maxLength, 40);
case SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMain:
case SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneMobile:
case SbmDbDfn_Control.ColumnIdx.UserAccount_PhoneAlt:
return Math.Min(maxLength, 20);
case SbmDbDfn_Control.ColumnIdx.ItemParam_Value:
if (maxLength == 0 || maxLength > 2048) return 2048;
break;
}
return maxLength;
}
//-------------------------------------------------------------------
}
//=======================================================================
}