v1.2.3.1
This commit is contained in:
@@ -20,7 +20,6 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SaxInternals internals;
|
||||
private readonly String alias_ActivityIndex = SaxActivityMgr_Dbas.aliasActivityIndex;
|
||||
private readonly String alias_ActivityIndex_UserActivity = SaxActivityMgr_Dbas.aliasActivityIndex_UserActivity;
|
||||
protected class IndexStatsData
|
||||
@@ -35,13 +34,11 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
protected SaxActivityConsole_Web(SaxSessionContext sessionContext) :
|
||||
base(sessionContext)
|
||||
{
|
||||
internals = new SaxInternals(sessionContext);
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
internals.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -78,8 +75,8 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
if (!context.IsValid()) return results;
|
||||
|
||||
// Columns to query.
|
||||
ColumnDfn colItemType = internals.ActivityMgr.GetActivityIndexColumnDfn(SaxActivityIndex.Column.ItemType);
|
||||
ColumnDfn colItemId = internals.ActivityMgr.GetActivityIndexColumnDfn(SaxActivityIndex.Column.ItemId);
|
||||
ColumnDfn colItemType = Internals.ActivityMgr.GetActivityIndexColumnDfn(SaxActivityIndex.Column.ItemType);
|
||||
ColumnDfn colItemId = Internals.ActivityMgr.GetActivityIndexColumnDfn(SaxActivityIndex.Column.ItemId);
|
||||
String colDataNameEffectiveOn = "EffectiveOn";
|
||||
|
||||
// Query the Activity Index.
|
||||
@@ -102,7 +99,7 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
prmActivityIndex.Alias_ActivityIndex = alias_ActivityIndex;
|
||||
prmActivityIndex.ResultsPaging.PageNo = 1;
|
||||
prmActivityIndex.ResultsPaging.PageLength = 100;
|
||||
query.Filters.AddRange(internals.ActivityMgr.GetActivityIndexQueryFilter(prmActivityIndex));
|
||||
query.Filters.AddRange(Internals.ActivityMgr.GetActivityIndexQueryFilter(prmActivityIndex));
|
||||
|
||||
// First pass, note the activity Item and effective date.
|
||||
List<ActivityData_Web> activityDataList = new List<ActivityData_Web>();
|
||||
@@ -382,7 +379,7 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
List<IndexEntryData> indexEntryDataList = GetEntriesForIndex(indexData);
|
||||
|
||||
// Retrieve existing index entries for the item.
|
||||
List<SaxActivityIndex> indexEntries = internals.ActivityMgr.GetActivityIndexListForItem(indexData.ItemId);
|
||||
List<SaxActivityIndex> indexEntries = Internals.ActivityMgr.GetActivityIndexListForItem(indexData.ItemId);
|
||||
foreach (SaxActivityIndex indexEntry in indexEntries)
|
||||
{
|
||||
// Is the index entry still required.
|
||||
@@ -396,9 +393,9 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
if (!indexEntry.EffectiveOn.Equals(indexEntrydata.EffectiveOn))
|
||||
{
|
||||
indexEntry.EffectiveOn = indexEntrydata.EffectiveOn;
|
||||
if (internals.ActivityMgr.UpdateActivityIndex(indexEntry, dbUpdateInfo))
|
||||
if (Internals.ActivityMgr.UpdateActivityIndex(indexEntry, dbUpdateInfo))
|
||||
stats.EntriesUpdated++;
|
||||
else SaLogger.Warn(fn + " Failed to update Activity Index - " + internals.ActivityMgr.ErrorStateMessage);
|
||||
else SaLogger.Warn(fn + " Failed to update Activity Index - " + Internals.ActivityMgr.ErrorStateMessage);
|
||||
}
|
||||
// Remove the entry from the 'required' list.
|
||||
// Entries remaining in this list will be created.
|
||||
@@ -407,18 +404,18 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
else
|
||||
{
|
||||
// Index entry no longer required.
|
||||
if (internals.ActivityMgr.DeleteActivityIndex(indexEntry, dbUpdateInfo))
|
||||
if (Internals.ActivityMgr.DeleteActivityIndex(indexEntry, dbUpdateInfo))
|
||||
stats.EntriesDeleted++;
|
||||
else SaLogger.Warn(fn + " Failed to delete Activity Index - " + internals.ActivityMgr.ErrorStateMessage);
|
||||
else SaLogger.Warn(fn + " Failed to delete Activity Index - " + Internals.ActivityMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
// The remaining required Index entries will be created.
|
||||
foreach (IndexEntryData indexEntry in indexEntryDataList)
|
||||
{
|
||||
SaxActivityIndex itemIndexEntry = internals.ActivityMgr.CreateActivityIndex(indexEntry.ItemId, indexEntry.SportId, indexEntry.RegionId, indexEntry.EffectiveOn);
|
||||
if (internals.ActivityMgr.InsertActivityIndex(itemIndexEntry, dbUpdateInfo))
|
||||
SaxActivityIndex itemIndexEntry = Internals.ActivityMgr.CreateActivityIndex(indexEntry.ItemId, indexEntry.SportId, indexEntry.RegionId, indexEntry.EffectiveOn);
|
||||
if (Internals.ActivityMgr.InsertActivityIndex(itemIndexEntry, dbUpdateInfo))
|
||||
stats.EntriesInserted++;
|
||||
else SaLogger.Warn(fn + " Failed to insert Activity Index - " + internals.ActivityMgr.ErrorStateMessage);
|
||||
else SaLogger.Warn(fn + " Failed to insert Activity Index - " + Internals.ActivityMgr.ErrorStateMessage);
|
||||
}
|
||||
|
||||
// Log statistics.
|
||||
@@ -506,7 +503,7 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
if (!ItemId.IsValid(activityItemId)) return SetErrorState("Activity item id must be specified");
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
SaxUserActivity userActivity = internals.ActivityMgr.GetUserActivityForUserItem(userAccountId, activityItemId);
|
||||
SaxUserActivity userActivity = Internals.ActivityMgr.GetUserActivityForUserItem(userAccountId, activityItemId);
|
||||
if (userActivity != null)
|
||||
{
|
||||
// Update activity.
|
||||
@@ -515,10 +512,10 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
userActivity.ViewedAtFirst = now;
|
||||
userActivity.ViewedAtLast = now;
|
||||
userActivity.Status = SaxUserActivity.DefaultStatus;
|
||||
if (!internals.ActivityMgr.UpdateUserActivity(userActivity, dbUpdateInfo))
|
||||
if (!Internals.ActivityMgr.UpdateUserActivity(userActivity, dbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update User Activity for viewing: " + internals.ActivityMgr.ErrorStateMessage);
|
||||
return SetErrorState(internals.ActivityMgr.ErrorStateMessage);
|
||||
SaLogger.Warn(fn + " Failed to update User Activity for viewing: " + Internals.ActivityMgr.ErrorStateMessage);
|
||||
return SetErrorState(Internals.ActivityMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -538,7 +535,7 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
if (!ItemId.IsValid(activityItemId)) return SetErrorState("Activity item id must be specified");
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
SaxUserActivity userActivity = internals.ActivityMgr.GetUserActivityForUserItem(userAccountId, activityItemId);
|
||||
SaxUserActivity userActivity = Internals.ActivityMgr.GetUserActivityForUserItem(userAccountId, activityItemId);
|
||||
if (userActivity != null)
|
||||
{
|
||||
if (userActivity.Reaction != activityReaction)
|
||||
@@ -553,10 +550,10 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
userActivity.ReactedAtFirst = now;
|
||||
userActivity.ReactedAtLast = now;
|
||||
userActivity.Status = SaxUserActivity.DefaultStatus;
|
||||
if (!internals.ActivityMgr.UpdateUserActivity(userActivity, dbUpdateInfo))
|
||||
if (!Internals.ActivityMgr.UpdateUserActivity(userActivity, dbUpdateInfo))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to update User Activity with reaction: " + internals.ActivityMgr.ErrorStateMessage);
|
||||
return SetErrorState(internals.ActivityMgr.ErrorStateMessage);
|
||||
SaLogger.Warn(fn + " Failed to update User Activity with reaction: " + Internals.ActivityMgr.ErrorStateMessage);
|
||||
return SetErrorState(Internals.ActivityMgr.ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,9 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
{
|
||||
String fn = GetType().Name + ".RefreshRegions";
|
||||
if (!RegionsSupported) throw new NotSupportedException(fn + " Regions not supported.");
|
||||
SaLogger.Info(fn + " START.", false);
|
||||
|
||||
try
|
||||
{
|
||||
DateTime startedAt = DateTime.Now;
|
||||
|
||||
// Refreshed lists will be populated in isolation and then used to instantaneously replace the cache lists.
|
||||
@@ -166,7 +168,12 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
regionsData.regionDataMap = newRegionDataMap;
|
||||
regionsData.activeRegionDataList = newActiveRegionDataList;
|
||||
}
|
||||
SaLogger.Info(fn + " END. Regions found: " + regionsData.regionDataMap.Count + ". Elapsed: " + DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds));
|
||||
SaLogger.Info(fn + " Regions found: " + regionsData.regionDataMap.Count + ". Elapsed: " + DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds));
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Error(fn + ExceptionUtil.GetLogMessage(exc, "refreshing Regions cache"));
|
||||
}
|
||||
}
|
||||
private static bool IsRegionActive(Dictionary<SysId, SaxRegion.Data> regionDataMap, SaxRegion.Data regionData)
|
||||
{
|
||||
@@ -223,7 +230,9 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
{
|
||||
String fn = GetType().Name + ".RefreshSports";
|
||||
if (!SportsSupported) throw new NotSupportedException(fn + " Sports not supported.");
|
||||
SaLogger.Info(fn + " START.", false);
|
||||
|
||||
try
|
||||
{
|
||||
DateTime startedAt = DateTime.Now;
|
||||
|
||||
// Refreshed lists will be populated in isolation and then used to instantaneously replace the cache lists.
|
||||
@@ -255,7 +264,12 @@ namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
sportsData.sportDataMap = newSportDataMap;
|
||||
sportsData.activeSportDataList = newActiveSportDataList;
|
||||
}
|
||||
SaLogger.Info(fn + " END. Sports found: " + sportsData.sportDataMap.Count + ". Elapsed: " + DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds));
|
||||
SaLogger.Info(fn + " Sports found: " + sportsData.sportDataMap.Count + ". Elapsed: " + DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds));
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Error(fn + ExceptionUtil.GetLogMessage(exc, "refreshing Sports cache"));
|
||||
}
|
||||
}
|
||||
private static bool IsSportActive(Dictionary<SysId, SaxSport.Data> sportDataMap, SaxSport.Data sportData)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Consoles;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaxSessionDataConsole_Web : SaxSessionDataConsole
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SaxSessionDataConsole_Web(SaxSessionContext sessionContext) :
|
||||
base(sessionContext)
|
||||
{
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -43,6 +43,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
|
||||
// Protected construction.
|
||||
protected SaxController_Base(SaxLocaliser localiser)
|
||||
{
|
||||
CreatedAt = DateTime.Now;
|
||||
Localiser = localiser;
|
||||
|
||||
// Initialise console (debug) logging listener.
|
||||
@@ -60,6 +61,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public DateTime CreatedAt { get; }
|
||||
public bool DebugMode { get; } = SacsSystem.DebugMode;
|
||||
protected SaxApplication_Web App { get { return SaxApplication_Web.WebApp; } }
|
||||
public SaxAppConfig AppConfig { get { return App.AppConfig; } }
|
||||
@@ -102,6 +104,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
|
||||
public SaxInternals Internals { get { if (internals == null) internals = new SaxInternals(SessionContext); return internals; } }
|
||||
// Consoles.
|
||||
public SaxDataCacheConsole DataCacheConsole { get { return Internals.DataCacheConsole; } }
|
||||
public SaxSessionDataConsole SessionDataConsole { get { return Internals.SessionDataConsole; } }
|
||||
public SaxActivityConsole ActivityConsole { get { return Internals.ActivityConsole; } }
|
||||
// Managers.
|
||||
public SaxReferenceMgr ReferenceMgr { get { return Internals.ReferenceMgr; } }
|
||||
@@ -161,7 +164,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
|
||||
//-------------------------------------------------------------------
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuting" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
|
||||
//if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuting" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
|
||||
|
||||
// Refreh model properties.
|
||||
SaxModel_Base baseModel = ViewData.Model as SaxModel_Base;
|
||||
@@ -171,7 +174,7 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
|
||||
}
|
||||
public override void OnActionExecuted(ActionExecutedContext filterContext)
|
||||
{
|
||||
if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuted" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
|
||||
//if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuted" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
|
||||
|
||||
// Refreh model properties.
|
||||
SaxModel_Base baseModel = ViewData.Model as SaxModel_Base;
|
||||
@@ -296,7 +299,17 @@ namespace Saxonite.Net.Core.Web.Base.Controllers
|
||||
//-------------------------------------------------------------------
|
||||
// Session.
|
||||
//-------------------------------------------------------------------
|
||||
public bool ValidUserSession { get { return SessionData?.ValidUserSession ?? false; } }
|
||||
public bool ValidUserSession
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SessionData == null || !SessionData.ValidUserSession) return false;
|
||||
SaxSessionDataConsole sessionDataConsole = SessionDataConsole;
|
||||
if (sessionDataConsole != null)
|
||||
sessionDataConsole.RecordUserActive(UserAccountId, CreatedAt);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public SysId UserAccountId { get { return SessionData?.User?.UserAccountId ?? null; } }
|
||||
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SaxSystem.ComputerName); } }
|
||||
// Referrer.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
@@ -63,6 +64,7 @@ namespace Saxonite.Net.Core.Web.Base.Models
|
||||
protected SaxInternals Internals { get { if (internals == null) internals = new SaxInternals(SessionContext); return internals; } }
|
||||
// Consoles.
|
||||
protected SaxDataCacheConsole DataCacheConsole { get { return Internals.DataCacheConsole; } }
|
||||
protected SaxSessionDataConsole SessionDataConsole { get { return Internals.SessionDataConsole; } }
|
||||
protected SaxActivityConsole ActivityConsole { get { return Internals.ActivityConsole; } }
|
||||
// Managers.
|
||||
public SaxReferenceMgr ReferenceMgr { get { return Internals.ReferenceMgr; } }
|
||||
@@ -189,8 +191,10 @@ namespace Saxonite.Net.Core.Web.Base.Models
|
||||
}
|
||||
public bool IsPaged { get { return paging.Paged; } }
|
||||
public uint PageNo { get { return paging.PageNo; } set { paging.PageNo = value; } }
|
||||
public String PageNoValue { get { return paging.PageNo.ToString(); } set { paging.PageNo = (uint)StringUtil.ToInt(value); } }
|
||||
public ushort PageLength { get { return paging.PageLength; } set { paging.PageLength = value; } }
|
||||
public uint PageCount { get { return (PageLength > 0 ? (uint)Math.Ceiling((decimal)ItemTotal / PageLength) : 0); } }
|
||||
public String PageLengthValue { get { return paging.PageLength.ToString(); } set { paging.PageLength = (ushort)StringUtil.ToShort(value); } }
|
||||
public uint PageCount { get { return (PageLength > 0 ? (uint)Math.Ceiling((decimal)ItemTotal / paging.PageLength) : 0); } }
|
||||
public ushort ItemCount { get; set; }
|
||||
private ulong itemTotal = 0;
|
||||
public ulong ItemTotal
|
||||
@@ -241,6 +245,17 @@ namespace Saxonite.Net.Core.Web.Base.Models
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Display data - Dates.
|
||||
public String FormatDateForDisplay(DateTime value)
|
||||
{
|
||||
return DateUtil.Format(value, "d-MMM-yy", SessionCulture);
|
||||
}
|
||||
public String FormatDateTimeForDisplay(DateTime value)
|
||||
{
|
||||
return StringUtil.TrimAll(DateUtil.Format(value, "d-MMM-yy HH:mm", SessionCulture));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Form data - Dates.
|
||||
// Format may depend on locale, but as long as these methods are used consistently,
|
||||
@@ -362,13 +377,16 @@ namespace Saxonite.Net.Core.Web.Base.Models
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>List of Organisation Categories for dropdown.</summary>
|
||||
/// <summary>
|
||||
/// List of Organisation Categories for dropdown.
|
||||
/// <para>NB Does not include 'Partner' or 'Other'.</para>
|
||||
/// </summary>
|
||||
public IEnumerable<SelectListItem> OrganisationCategoriesForSelect
|
||||
{
|
||||
get
|
||||
{
|
||||
List<SelectListItem> values = new List<SelectListItem>();
|
||||
foreach (TypeCodeDesc organisationCategory in OrganisationCategoryCodes)
|
||||
foreach (TypeCodeDesc organisationCategory in OrganisationCategoryCodes.FindAll(item => item.Type != (int)Sax.OrganisationCategory.Partner && item.Type != (int)Sax.OrganisationCategory.Other))
|
||||
values.Add(new SelectListItem(Localiser.GetOrganisationCategoryCaption((Sax.OrganisationCategory)organisationCategory.Type), organisationCategory.Code));
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,14 @@ namespace Saxonite.Net.Core.Web.Admin.Consoles
|
||||
throw new NotSupportedException(fn + " Data Cache Console not supported in Admin app.");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session data console.
|
||||
public override SaxSessionDataConsole GetSessionDataConsole(SaxSessionContext sessionContext)
|
||||
{
|
||||
// Method is called by Base Controller on ValidUserSession and must return null for Admin app.
|
||||
return null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Activity console.
|
||||
public override SaxActivityConsole CreateActivityConsole(SaxSessionContext sessionContext)
|
||||
|
||||
@@ -45,8 +45,13 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Get user account.
|
||||
SaxUserAccount userAccount = GetUserAccountForSignin(model, responseData);
|
||||
disposableItems.Add(userAccount);
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
@@ -55,6 +60,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
return Json(responseData.SetControlError(nameof(model.EmailAddress), errorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
responseData.Success = SessionData_Admin?.ValidUserSession ?? false;
|
||||
@@ -74,6 +80,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
public ActionResult Ajax_KeepLoggedIn(Model_Security model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_KeepLoggedIn";
|
||||
if (DebugMode) SaLogger.Debug(fn);
|
||||
AjaxResponse_KeepLoggedIn responseData = new AjaxResponse_KeepLoggedIn();
|
||||
|
||||
if (!ValidUserSession)
|
||||
@@ -96,43 +103,50 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
private SaxUserAccount GetUserAccountForSignin(Model_Security model, AjaxResponse_Data responseData)
|
||||
{
|
||||
String fn = GetType().Name + ".GetUserAccountForSignin";
|
||||
// Identify user account.
|
||||
SaxUserAccount userAccount = null;
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify user account.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
prmUserAccount.EmailAddress = model.EmailAddress;
|
||||
prmUserAccount.StatusCat = SaxUserAccount.StatusCat.Any;
|
||||
foreach (SaxUserAccount userAccountDuplicate in AccountMgr.GetUserAccountList(prmUserAccount))
|
||||
List<SaxUserAccount> userAccounts = AccountMgr.GetUserAccountList(prmUserAccount);
|
||||
disposableItems.AddRange(userAccounts);
|
||||
foreach (SaxUserAccount userAccountCandidate in userAccounts)
|
||||
{
|
||||
// Account must be active to allow sign-in.
|
||||
// NB Debug testing allows 'Awaiting' accounts to sign-in.
|
||||
if ((SaxSystem.DebugMode && userAccountDuplicate.Status == SaStatus.Awaiting) || userAccountDuplicate.IsStatusActive)
|
||||
if ((SaxSystem.DebugMode && userAccountCandidate.Status == SaStatus.Awaiting) || userAccountCandidate.IsStatusActive)
|
||||
{
|
||||
userAccount = userAccountDuplicate;
|
||||
userAccount = userAccountCandidate;
|
||||
break;
|
||||
}
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " with status " + SaxSystem.GetStatusDesc(userAccount.Status), true);
|
||||
}
|
||||
if (userAccount != null)
|
||||
{
|
||||
// Validate password.
|
||||
if (!SaxPasswordHelper.VerifyHashedPassword(userAccount, model.Password) && !(DebugMode && model.EmailAddress.EqualsCI("andy@sarand.com") && model.Password.EqualsCI("SolumForti")))
|
||||
{
|
||||
recordInvalidLoginAttempt(model, userAccount);
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " with invalid password. Attempt: " + userAccount.InvalidLoginCount, true);
|
||||
userAccount = null;
|
||||
}
|
||||
}
|
||||
if (userAccount == null && !responseData.HasControlErrors())
|
||||
responseData.SetControlError(nameof(model.EmailAddress), model.Localiser["security.msg.signin.invalid"]);
|
||||
|
||||
// Admin - Verify that user has System Admin role.
|
||||
if (!AccountMgr.UserHasRole(userAccount.Id, Sax.UserRole.SystemAdmin, SaxUserRole.StatusCat.ActiveOnly))
|
||||
else if (!AccountMgr.UserHasRole(userAccount.Id, Sax.UserRole.SystemAdmin, SaxUserRole.StatusCat.ActiveOnly))
|
||||
{
|
||||
recordInvalidLoginAttempt(model, userAccount);
|
||||
SaLogger.Warn(fn + " Attempt to sign-in to User Account for " + model.EmailAddress + " without SystemAdmin role. Attempt: " + userAccount.InvalidLoginCount, true);
|
||||
userAccount = null;
|
||||
}
|
||||
}
|
||||
if (userAccount == null && !responseData.HasControlErrors())
|
||||
responseData.SetControlError(nameof(model.EmailAddress), model.Localiser["security.msg.signin.invalid"]);
|
||||
}
|
||||
|
||||
return userAccount;
|
||||
}
|
||||
private void recordInvalidLoginAttempt(Model_Security model, SaxUserAccount userAccount)
|
||||
@@ -167,8 +181,13 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession)
|
||||
return Json(responseData.SetSessionExpired(messageTitle, Localiser["security.msg.warn.sessionExpired"]));
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Retrieve user account - in case sign-out needs to be recorded.
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(SessionData_Admin.User.UserAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " System error on sign-out - failed to retrieve account details. Id: " + SysId.ToInt(SessionData_Admin.User.UserAccountId));
|
||||
@@ -178,6 +197,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
// Clear user session.
|
||||
CloseUserSession();
|
||||
SaLogger.Info(fn + " User session closed for " + userAccount.EmailAddress, true);
|
||||
}
|
||||
|
||||
// Clear 'Keep Logged In' cookie.
|
||||
ClearKeepLoggedInCookie();
|
||||
@@ -227,6 +247,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
AjaxResponse_ChangePassword responseData = new AjaxResponse_ChangePassword(model);
|
||||
String messageTitle = Localiser["security.caption.change.password"];
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// If 'Request Password' encrypted params (from email link) are present,
|
||||
// Session is not required and password can be set directly against the user.
|
||||
SaxUserAccount userAccount = null;
|
||||
@@ -237,6 +261,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
// Retrieve user account details and validate email address.
|
||||
userAccount = AccountMgr.GetUserAccountById(requestPasswordParams.UserAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
if (requestPasswordParams.IsValid(userAccount))
|
||||
{
|
||||
validRequestPasswordParams = true;
|
||||
@@ -257,6 +282,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (userAccount == null && SessionData_Admin != null)
|
||||
{
|
||||
userAccount = AccountMgr.GetUserAccountById(SessionData_Admin.User.UserAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
}
|
||||
if (userAccount == null)
|
||||
return Json(responseData.SetControlError(nameof(model.Password), "System error - failed to retrieve account details."));
|
||||
@@ -299,6 +325,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
responseData.Success = true;
|
||||
if (validRequestPasswordParams)
|
||||
responseData.SetMessage(messageTitle, Localiser["security.msg.request.password.saved"]);
|
||||
}
|
||||
|
||||
return Json(responseData);
|
||||
}
|
||||
@@ -327,8 +354,13 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Retrieve user account.
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountByEmailAddress(model.EmailAddress);
|
||||
disposableItems.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
SaLogger.Warn(fn + " Unable to send password request email to " + model.EmailAddress + " - account does not exist");
|
||||
else if (!userAccount.IsStatusActive)
|
||||
@@ -341,6 +373,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
SaLogger.Info(fn + " Password request email sent to " + model.EmailAddress, true);
|
||||
else SaLogger.Warn(fn + " Failed to send password request email to " + model.EmailAddress);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
responseData.Success = true;
|
||||
|
||||
@@ -26,14 +26,19 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
public String Title { get; set; }
|
||||
public String FirstName { get; set; }
|
||||
public String LastName { get; set; }
|
||||
public String RegionNameCountry { get; set; }
|
||||
public String RegionNameProvince { get; set; }
|
||||
public int UserRoleCount { get; set; }
|
||||
public bool? SystemAdmin { get; set; } = null;
|
||||
public String LastLoginAt { get; set; }
|
||||
}
|
||||
private class UserData_Full : UserData_List
|
||||
{
|
||||
public String RegionIdCountry { get; set; }
|
||||
public String RegionIdProvince { get; set; }
|
||||
public List<String> userRoleCodes { get; } = new List<string>();
|
||||
}
|
||||
private void PopulateUserResponseData(UserData_List data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_List data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
{
|
||||
data.Id = SysId.ToString(user.Id);
|
||||
data.EmailAddress = user.EmailAddress;
|
||||
@@ -41,14 +46,20 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
data.Title = user.Title;
|
||||
data.FirstName = user.FirstName;
|
||||
data.LastName = user.LastName;
|
||||
data.RegionNameCountry = model.GetRegionName(user.RegionIdCountry);
|
||||
data.RegionNameProvince = model.GetRegionName(user.RegionIdProvince);
|
||||
data.UserRoleCount = userRoles?.GetUserRolesByStatus(SaStatus.Active).Count ?? 0;
|
||||
data.SystemAdmin = (userRoles != null && userRoles.Exists(item => item.UserRole == Sax.UserRole.SystemAdmin) ? true : (bool?)null);
|
||||
data.LastLoginAt = model.FormatDateTimeForDisplay(user.LastLoginAt);
|
||||
data.StatusCode = user.StatusCode;
|
||||
data.StatusDesc = user.StatusDesc;
|
||||
}
|
||||
private void PopulateUserResponseData(UserData_Full data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_Full data, SaxUserAccount user, List<SaxUserRole> userRoles)
|
||||
{
|
||||
PopulateUserResponseData(data as UserData_List, user, userRoles);
|
||||
PopulateUserResponseData(model, data as UserData_List, user, userRoles);
|
||||
|
||||
data.RegionIdCountry = SysId.ToString(user.RegionIdCountry);
|
||||
data.RegionIdProvince = SysId.ToString(user.RegionIdProvince);
|
||||
|
||||
if (userRoles != null)
|
||||
{
|
||||
@@ -122,19 +133,18 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
ColumnDfn colTitle = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.Title);
|
||||
ColumnDfn colFirstName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.FirstName);
|
||||
ColumnDfn colLastName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.LastName);
|
||||
ColumnDfn colCountryName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.RegionCountry_Name);
|
||||
ColumnDfn colProvinceName = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.RegionProvince_Name);
|
||||
ColumnDfn colUserRoleCount = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.UserRoleCount);
|
||||
ColumnDfn colSystemAdminUser = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.SystemAdminUser);
|
||||
ColumnDfn colLastLogin = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.LastLoginAt);
|
||||
ColumnDfn colStatus = AccountMgr.GetUserAccountColumnDfn(SaxUserAccount.Column.Status);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colId,
|
||||
colEmail,
|
||||
colTitle,
|
||||
colFirstName,
|
||||
colLastName,
|
||||
colUserRoleCount,
|
||||
colSystemAdminUser,
|
||||
colStatus
|
||||
colId, colEmail, colTitle, colFirstName, colLastName,
|
||||
colCountryName, colProvinceName,
|
||||
colUserRoleCount, colSystemAdminUser,
|
||||
colLastLogin, colStatus
|
||||
};
|
||||
|
||||
// Query items.
|
||||
@@ -150,8 +160,11 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
Title = values.GetString(colTitle.DataName),
|
||||
FirstName = values.GetString(colFirstName.DataName),
|
||||
LastName = values.GetString(colLastName.DataName),
|
||||
RegionNameCountry = values.GetString(colCountryName.DataName),
|
||||
RegionNameProvince = values.GetString(colProvinceName.DataName),
|
||||
UserRoleCount = StringUtil.ToInt(values.GetString(colUserRoleCount.DataName)),
|
||||
SystemAdmin = StringUtil.ToBool(values.GetString(colSystemAdminUser.DataName)),
|
||||
LastLoginAt = model.FormatDateTimeForDisplay(values.GetDateTime(colLastLogin.DataName)),
|
||||
StatusCode = values.GetString(colStatus.DataName),
|
||||
StatusDesc = SacsSystem.GetStatusDescForCode(values.GetString(colStatus.DataName))
|
||||
};
|
||||
@@ -193,6 +206,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
@@ -200,6 +217,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
|
||||
// Retrieve item.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(user);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + userAccountId + "'");
|
||||
@@ -207,8 +225,9 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
PopulateUserResponseData(model, responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -229,6 +248,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify user.
|
||||
if (StringUtil.IsEmpty(model.UserEmailAddress))
|
||||
{
|
||||
@@ -238,6 +261,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
|
||||
// Retrieve user.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountByEmailAddress(model.UserEmailAddress);
|
||||
disposableItems.Add(user);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Email: " + model.UserEmailAddress);
|
||||
@@ -245,8 +269,9 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
PopulateUserResponseData(model, responseData.user, user, GetUserRoles(user.Id).GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -272,9 +297,14 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (responseData.HasControlErrors())
|
||||
return Json(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Retrieve existing item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(user);
|
||||
if (user == null && SysId.IsValid(userAccountId))
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + model.UserAccountId + "'");
|
||||
@@ -284,6 +314,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
// User roles, including deleted in case of reassignment.
|
||||
List<SaxUserRole> userRoles = new List<SaxUserRole>();
|
||||
if (user != null) userRoles = GetUserRoles(user.Id, SaxUserRole.StatusCat.Any);
|
||||
disposableItems.AddRange(userRoles);
|
||||
if (model.UserRoleCodes != null)
|
||||
{
|
||||
List<String> userRoleCodes = model.GetUserRoleCodes();
|
||||
@@ -322,6 +353,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
user.FirstName = model.UserFirstName;
|
||||
if (model.UserLastName != null)
|
||||
user.LastName = model.UserLastName;
|
||||
if (model.UserRegionIdCountry != null)
|
||||
user.RegionIdCountry = model.UserRegionIdCountry.ToSysId();
|
||||
if (model.UserRegionIdProvince != null)
|
||||
user.RegionIdProvince = model.UserRegionIdProvince.ToSysId();
|
||||
if (model.UserStatusCode != null)
|
||||
user.Status = model.UserStatus;
|
||||
|
||||
@@ -366,8 +401,9 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, user, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
PopulateUserResponseData(model, responseData.user, user, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
@@ -387,9 +423,14 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Retrieve user.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
SaxUserAccount userAccount = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(userAccount);
|
||||
if (userAccount == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + model.UserAccountId + "'");
|
||||
@@ -398,6 +439,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
|
||||
// User roles.
|
||||
List<SaxUserRole> userRoles = GetUserRoles(userAccount.Id, SaxUserRole.StatusCat.Any);
|
||||
disposableItems.AddRange(userRoles);
|
||||
bool systemAdmin = userRoles.Exists(item => item.UserRole == Sax.UserRole.SystemAdmin);
|
||||
|
||||
// Email types to send.
|
||||
@@ -431,9 +473,10 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
}
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(responseData.user, userAccount, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
PopulateUserResponseData(model, responseData.user, userAccount, userRoles.GetUserRolesByStatus(SaStatus.Active));
|
||||
responseData.SetNotification(messageTitle, "Emails sent: " + emailsSentCount);
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Admin.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.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
partial class UsersOnlineController
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// User data.
|
||||
private class UserData_List : AjaxResponse_Data.ItemData_Base
|
||||
{
|
||||
public String EmailAddress { get; set; }
|
||||
public String DisplayName { get; set; }
|
||||
public String Title { get; set; }
|
||||
public String FirstName { get; set; }
|
||||
public String LastName { get; set; }
|
||||
public String LastLoginAt { get; set; }
|
||||
public String OnlineAt { get; set; }
|
||||
}
|
||||
private class UserData_Full : UserData_List
|
||||
{
|
||||
}
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_List data, SaxUserAccount user, SaxUserOnline userOnline)
|
||||
{
|
||||
data.Id = SysId.ToString(user.Id);
|
||||
data.EmailAddress = user.EmailAddress;
|
||||
data.DisplayName = user.GetDisplayName();
|
||||
data.Title = user.Title;
|
||||
data.FirstName = user.FirstName;
|
||||
data.LastName = user.LastName;
|
||||
data.LastLoginAt = model.FormatDateTimeForDisplay(user.LastLoginAt);
|
||||
if (userOnline != null)
|
||||
data.OnlineAt = model.FormatDateTimeForDisplay(userOnline.OnlineAt);
|
||||
}
|
||||
private void PopulateUserResponseData(SaxModel_Admin model, UserData_Full data, SaxUserAccount user, SaxUserOnline userOnline)
|
||||
{
|
||||
PopulateUserResponseData(model, data as UserData_List, user, userOnline);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get User List ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_UserList : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_UserList(SaxModel_Admin model) : base(model) { }
|
||||
// User list.
|
||||
public List<UserData_List> Users { get; } = new List<UserData_List>();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("UsersOnline/Ajax/GetList")]
|
||||
[Route("UsersOnline/Ajax/GetUsers")]
|
||||
[Route("UsersOnline/Ajax/GetUserList")]
|
||||
public IActionResult Ajax_GetUsersOnlineList(Model_User model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetUsersOnlineList";
|
||||
String messageTitle = Localiser["label.users.online"];
|
||||
AjaxResponse_UserList responseData = new AjaxResponse_UserList(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Item filter.
|
||||
SaxUserOnline.Params prmUserOnline = new SaxUserOnline.Params();
|
||||
prmUserOnline.UserFilterPartial = model.Filter.User;
|
||||
prmUserOnline.SportIdsIncluded.AddId(model.Filter.UserSportId.ToSysId());
|
||||
prmUserOnline.RegionIdsIncluded.AddId(model.Filter.UserRegionId.ToSysId());
|
||||
model.Paging.ItemTotal = (ulong)AccountMgr.GetUserOnlineCount(prmUserOnline);
|
||||
model.PopulatePagingTo(prmUserOnline.ResultsPaging);
|
||||
|
||||
// Item columns.
|
||||
ColumnDfn colUserAccountId = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.UserAccountId);
|
||||
ColumnDfn colEmail = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.EmailAddress);
|
||||
ColumnDfn colTitle = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.Title);
|
||||
ColumnDfn colFirstName = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.FirstName);
|
||||
ColumnDfn colLastName = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.LastName);
|
||||
ColumnDfn colLastLogin = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.LastLoginAt);
|
||||
ColumnDfn colOnlineAt = AccountMgr.GetUserOnlineColumnDfn(SaxUserOnline.Column.OnlineAt);
|
||||
List<ColumnDfn> columns = new List<ColumnDfn>()
|
||||
{
|
||||
colUserAccountId,
|
||||
colEmail, colTitle, colFirstName, colLastName,
|
||||
colLastLogin, colOnlineAt
|
||||
};
|
||||
|
||||
// Query items.
|
||||
using (DbResultSet resultSet = AccountMgr.ExecuteUserOnlineQuery(columns, prmUserOnline))
|
||||
{
|
||||
while (resultSet != null && resultSet.HasRows && resultSet.NextRecord())
|
||||
{
|
||||
NamedValue.Map values = resultSet.GetRecordValues();
|
||||
UserData_List userData = new UserData_List()
|
||||
{
|
||||
Id = values.GetString(colUserAccountId.DataName),
|
||||
EmailAddress = values.GetString(colEmail.DataName),
|
||||
Title = values.GetString(colTitle.DataName),
|
||||
FirstName = values.GetString(colFirstName.DataName),
|
||||
LastName = values.GetString(colLastName.DataName),
|
||||
LastLoginAt = model.FormatDateTimeForDisplay(values.GetDateTime(colLastLogin.DataName)),
|
||||
OnlineAt = model.FormatDateTimeForDisplay(values.GetDateTime(colOnlineAt.DataName)),
|
||||
};
|
||||
userData.DisplayName = SaxUserAccount.GetDisplayName(userData.Title, userData.FirstName, userData.LastName);
|
||||
responseData.Users.Add(userData);
|
||||
}
|
||||
}
|
||||
if (model.Paging.IsPaged)
|
||||
model.Paging.ItemCount = (ushort)responseData.Users.Count;
|
||||
|
||||
// Complete response.
|
||||
responseData.SetPaging(model);
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get User ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponse_User : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_User(SaxModel_Admin model) : base(model) { }
|
||||
// User details.
|
||||
public UserData_Full user { get; } = new UserData_Full();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("UsersOnline/Ajax/GetItem")]
|
||||
[Route("UsersOnline/Ajax/GetUser")]
|
||||
public IActionResult Ajax_GetUser(Model_User model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetUser";
|
||||
String messageTitle = Localiser["user.caption.user"];
|
||||
AjaxResponse_User responseData = new AjaxResponse_User(model);
|
||||
|
||||
// Validate session and referrer.
|
||||
if (!ValidReferer) return Forbid();
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// Identify item.
|
||||
SysId userAccountId = model.UserAccountId.ToSysId();
|
||||
if (!SysId.IsValid(userAccountId))
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.specified"]));
|
||||
|
||||
// Retrieve item.
|
||||
SaxUserAccount user = AccountMgr.GetUserAccountById(userAccountId);
|
||||
disposableItems.Add(user);
|
||||
if (user == null)
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve user for Id: '" + userAccountId + "'");
|
||||
return Json(responseData.SetMessage(messageTitle, Localiser["msg.error.item.id.not.found"]));
|
||||
}
|
||||
|
||||
// User Online.
|
||||
SaxUserOnline userOnline = AccountMgr.GetUserOnlineByUserAccountId(user.Id);
|
||||
disposableItems.Add(userOnline);
|
||||
|
||||
// Construct response.
|
||||
PopulateUserResponseData(model, responseData.user, user, userOnline);
|
||||
responseData.Success = true;
|
||||
}
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Core.Web.Admin.Models;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Controllers;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
//=======================================================================
|
||||
public partial class UsersOnlineController : SaxController_Admin
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public UsersOnlineController(SaxLocaliser localiser, ILogger<HomeController> logger) :
|
||||
base(localiser, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
[HttpGet]
|
||||
public IActionResult Index(String sta)
|
||||
{
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return RedirectToAction("", "");
|
||||
|
||||
// Paging.
|
||||
Model_UsersOnline model = new Model_UsersOnline(Localiser);
|
||||
model.Paging.PageNo = 1;
|
||||
model.Paging.PageLength = 24;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -67,6 +67,8 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public String UserTitle { get; set; }
|
||||
public String UserFirstName { get; set; }
|
||||
public String UserLastName { get; set; }
|
||||
public String UserRegionIdCountry { get; set; }
|
||||
public String UserRegionIdProvince { get; set; }
|
||||
public String UserRoleCodeDelim = ",";
|
||||
public new List<String> UserRoleCodes { get; set; }
|
||||
public List<String> GetUserRoleCodes()
|
||||
@@ -92,6 +94,12 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
// User.
|
||||
public bool ValidateUserData(SaxController_Base.AjaxResponse_Data responseData)
|
||||
{
|
||||
String fn = GetType().Name + ".ValidateUserData";
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsHierarchyItem> disposableItems = new DisposableCollection<SacsHierarchyItem>())
|
||||
{
|
||||
|
||||
// User email.
|
||||
if (UserEmailAddress != null)
|
||||
{
|
||||
@@ -142,6 +150,61 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
responseData.SetControlError(nameof(UserLastName), Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName)]);
|
||||
}
|
||||
|
||||
// Country region.
|
||||
SaxRegion regionCountry = null;
|
||||
if (UserRegionIdCountry != null)
|
||||
{
|
||||
if (!SysId.IsValid(UserRegionIdCountry.ToSysId()))
|
||||
responseData.SetControlError(nameof(UserRegionIdCountry), Localiser["msg.validation.mandatory.value"]);
|
||||
else
|
||||
{
|
||||
regionCountry = ReferenceMgr.GetRegionById(UserRegionIdCountry.ToSysId());
|
||||
disposableItems.Add(regionCountry);
|
||||
if (regionCountry != null)
|
||||
{
|
||||
if (regionCountry.RegionType != Sax.RegionType.Country)
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid region type. Expected: Country. Found: " + regionCountry.RegionType.ToString());
|
||||
responseData.SetControlError(nameof(UserRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve region for Id: " + UserRegionIdCountry);
|
||||
responseData.SetControlError(nameof(UserRegionIdCountry), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Province region.
|
||||
SaxRegion regionProvince = null;
|
||||
if (UserRegionIdProvince != null)
|
||||
{
|
||||
if (!UserRegionIdProvince.IsEmpty())
|
||||
{
|
||||
regionProvince = ReferenceMgr.GetRegionById(UserRegionIdProvince.ToSysId());
|
||||
disposableItems.Add(regionProvince);
|
||||
if (regionProvince != null)
|
||||
{
|
||||
if (regionProvince.RegionType != Sax.RegionType.Province)
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid region type. Expected: Province . Found: " + regionCountry.RegionType.ToString());
|
||||
responseData.SetControlError(nameof(UserRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
else if (regionCountry != null && !regionProvince.RegionIdParent.Equals(regionCountry.Id))
|
||||
{
|
||||
SaLogger.Warn(fn + " Invalid province region parent. Expected: " + regionCountry.Id.ToString() + " . Found: " + regionCountry.RegionIdParent.ToString());
|
||||
responseData.SetControlError(nameof(UserRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SaLogger.Warn(fn + " Failed to retrieve region for Id: " + UserRegionIdProvince);
|
||||
responseData.SetControlError(nameof(UserRegionIdProvince), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User status.
|
||||
if (UserStatusCode != null)
|
||||
{
|
||||
@@ -151,6 +214,8 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
responseData.SetControlError(nameof(UserStatus), Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return !responseData.HasControlErrors();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
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 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_UsersOnline : SaxModel_Admin
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public Model_UsersOnline(SaxLocaliser localiser) :
|
||||
base(localiser)
|
||||
{
|
||||
AdditionalFiles_JS.Add("js/sax-usr-onl.js");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User filter properties.
|
||||
public class FilterData
|
||||
{
|
||||
public String User { get; set; }
|
||||
public String UserSportId { get; set; }
|
||||
public String UserRegionId { get; set; }
|
||||
}
|
||||
public FilterData Filter { get; } = new FilterData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User properties.
|
||||
public String UserId { get; set; }
|
||||
[EmailAddress]
|
||||
public String UserEmailAddress { get; set; }
|
||||
public String UserTitle { get; set; }
|
||||
public String UserFirstName { get; set; }
|
||||
public String UserLastName { get; set; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Saxonite.Net.Core.Web.Admin.App;
|
||||
using Saxonite.Net.Core.Web.Base.App;
|
||||
using Saxonite.Net.Core.Web.Base.Models;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -26,6 +27,27 @@ namespace Saxonite.Net.Core.Web.Admin.Models
|
||||
public SaxSessionData_Admin SessionData_Admin { get { return SessionData as SaxSessionData_Admin; } }
|
||||
public SysId UserAccountId { get { return SessionData_Admin?.User?.UserAccountId ?? null; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Reference data.
|
||||
//-------------------------------------------------------------------
|
||||
public String GetSportName(SysId sportId)
|
||||
{
|
||||
using (SaxSport sport = ReferenceMgr.GetSportById(sportId))
|
||||
{
|
||||
if (sport != null) return sport.Name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String GetRegionName(SysId regionId)
|
||||
{
|
||||
using (SaxRegion region = ReferenceMgr.GetRegionById(regionId))
|
||||
{
|
||||
if (region != null) return region.Name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -330,6 +330,12 @@
|
||||
<data name="label.select" xml:space="preserve">
|
||||
<value>Select</value>
|
||||
</data>
|
||||
<data name="label.select.country" xml:space="preserve">
|
||||
<value>Select Country</value>
|
||||
</data>
|
||||
<data name="label.select.province" xml:space="preserve">
|
||||
<value>Select Province</value>
|
||||
</data>
|
||||
<data name="label.selected.count" xml:space="preserve">
|
||||
<value>{0} selected</value>
|
||||
</data>
|
||||
@@ -369,6 +375,9 @@
|
||||
<data name="label.user.roles" xml:space="preserve">
|
||||
<value>User roles</value>
|
||||
</data>
|
||||
<data name="label.users.online" xml:space="preserve">
|
||||
<value>Users online</value>
|
||||
</data>
|
||||
<data name="label.yes" xml:space="preserve">
|
||||
<value>Yes</value>
|
||||
</data>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<script type="text/javascript">
|
||||
sax.dlg.title.createOrganisation = '@Localiser.GetJavascriptText("organisation.caption.organisation.create")';
|
||||
sax.dlg.title.updateOrganisation = '@Localiser.GetJavascriptText("organisation.caption.organisation.update")';
|
||||
sax.dlg.title.selectRegion = '@Localiser.GetJavascriptText("region.caption.region.select")';
|
||||
sax.dlg.title.selectRegion = '@Localiser.GetJavascriptText("label.select.country")';
|
||||
sax.dlg.title.selectSport = '@Localiser.GetJavascriptText("sport.caption.sport.select")';
|
||||
</script>
|
||||
@using (@Html.BeginForm(FormMethod.Post, new { @id = "frmOrganisationId", @class = "sax-form" }))
|
||||
@@ -92,7 +92,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Organisation region *@
|
||||
@* Organisation country *@
|
||||
<div class="sax-form-control OrganisationRegionIdCountry">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
@* Scripts *@
|
||||
<script>
|
||||
var sax = sax || { page: {}, mdl: {}, url: {}, links: {}, form: {}, data: {}, ajax: {}, msg: {}, lbl: {}, dlg: { title: {}, btn: {} }, $frm: {}, $dlg: {}, $pnl: {} };
|
||||
var sax = sax || { page: {}, mdl: {}, url: {}, links: {}, form: {}, data: {}, ajax: {}, msg: {}, lbl: {}, dlg: { title: {}, btn: {} }, $frm: {}, $dlg: {}, $pnl: {}, session: {}, kli: {} };
|
||||
sax.url.base = '@Model.RedirectLocation.Base';
|
||||
sax.url.home = '@Model.RedirectLocation.Home';
|
||||
sax.url.sessionExpired = '@Model.RedirectLocation.Home_SessionExpired';
|
||||
@@ -79,10 +79,10 @@
|
||||
sax.msg.dataRefreshing = '@Localiser.GetJavascriptText("msg.data.refreshing")';
|
||||
sax.msg.dataQuerying = '@Localiser.GetJavascriptText("msg.data.querying")';
|
||||
sax.msg.dataNoneFound = '@Localiser.GetJavascriptText("msg.data.noneFound")';
|
||||
sax.sessionCookieName = '@Model.SessionCookieName';
|
||||
sax.session.cookieName = '@Model.SessionCookieName';
|
||||
sax.awaitingLogin = @awaitingLogin;
|
||||
sax.keepLoggedIn = @keepLoggedIn;
|
||||
sax.keepLoggedInDelay = @(Sax.Config.Admin.Session.Cookie.KeepLoggedInTimeoutMillis);
|
||||
sax.kli.active = @keepLoggedIn;
|
||||
sax.kli.interval = @(Sax.Config.Admin.Session.Cookie.KeepLoggedInTimeoutMillis);
|
||||
sax.debugMode = @debug;
|
||||
</script>
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
@Localiser["label.accounts"]
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('UsersOnline');">@Localiser["label.users.online"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('User');">@Localiser["user.caption.users"]</div>
|
||||
<div class="dropdown-item text-dark sax-action" onclick="sax.goToPage('Organisation');">@Localiser["organisation.caption.organisations"]</div>
|
||||
</div>
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@* Organisation Status *@
|
||||
@* User Status *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["label.status"]</div>
|
||||
<div class="col-sm-7">
|
||||
@@ -134,12 +134,12 @@
|
||||
<div class="sax-content">
|
||||
<div class="row">
|
||||
<div class="col-sm-4"><span class="UserDisplayName"></span></div>
|
||||
<div class="col-sm-4"><div>Roles: <span class="UserRoleCount"></span></div></div>
|
||||
<div class="col-sm-4 right"><div class="StatusDesc"></div></div>
|
||||
<div class="col-sm-4"><div class="UserLastLogin">Last login: <span class="UserLastLoginAt"></span></div></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4"></div>
|
||||
<div class="col-sm-4"><div class="UserRoles">Roles: <span class="UserRoleCount"></span></div></div>
|
||||
<div class="col-sm-4"><div class=""></div></div>
|
||||
<div class="col-sm-4 right"><div class="StatusDesc"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<script type="text/javascript">
|
||||
sax.dlg.title.createUser = '@Localiser.GetJavascriptText("user.caption.user.create")';
|
||||
sax.dlg.title.updateUser = '@Localiser.GetJavascriptText("user.caption.user.update")';
|
||||
sax.dlg.title.selectRegionCountry = '@Localiser.GetJavascriptText("label.select.country")';
|
||||
sax.dlg.title.selectRegionProvince = '@Localiser.GetJavascriptText("label.select.province")';
|
||||
sax.dlg.title.selectUserRoles = '@Localiser.GetJavascriptText("user.caption.select.user.roles")';
|
||||
sax.dlg.title.selectUserEmails = '@Localiser.GetJavascriptText("user.caption.select.user.emails")';
|
||||
sax.data.userRoleCodeDelim = '@Model.UserRoleCodeDelim';
|
||||
@@ -25,7 +27,7 @@
|
||||
@* User email *@
|
||||
<div class="sax-form-control UserEmailAddress">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserEmailAddress"><span>@Localiser["label.email.address"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
@@ -39,61 +41,103 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
/* Title */
|
||||
<div class="sax-form-control UserTitle">
|
||||
@* User Name *@
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label d-none d-sm-block">
|
||||
<label for="ifAccountEmailAddress"><span>@Localiser["label.name"]</span></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm row">
|
||||
|
||||
<div class="col-sm-4">
|
||||
@* Title *@
|
||||
<div class="sax-form-control UserTitle pr8">
|
||||
<div class="sax-label">
|
||||
<label for="cbUserTitle"><span><span class="required"></span> @Localiser["label.title"]</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control">
|
||||
@Html.DropDownListFor(model => model.UserTitle, Model.TitlesForSelect, Localiser["label.not.specified"], new { @id = "cbUserTitle", @class = "UserTitle sax-select" })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* User first name *@
|
||||
<div class="sax-form-control UserFirstName">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
@* User first name *@
|
||||
<div class="sax-form-control UserFirstName pr8">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserFirstName"><span>@Localiser["label.first.name"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control">
|
||||
@Html.TextBoxFor(model => model.UserFirstName, new { @id = "ifUserFirstName", @class = "UserFirstName sax-input", @maxlength = @Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName) })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-4">
|
||||
@* User last name *@
|
||||
<div class="sax-form-control UserLastName">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserLastName"><span>@Localiser["label.last.name"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control">
|
||||
@Html.TextBoxFor(model => model.UserLastName, new { @id = "ifUserLastName", @class = "UserLastName sax-input", @maxlength = @Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName) })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* User country *@
|
||||
<div class="sax-form-control UserRegionIdCountry">
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserRegionCaptionCountry"><span>@Localiser["label.country"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control row">
|
||||
@Html.HiddenFor(model => model.UserRegionIdCountry, new { @id = "ifUserRegionIdCountry", @class = "UserRegionIdCountry" })
|
||||
<div class="col"><input type="text" id="ifUserRegionCaptionCountry" class="UserRegionCaptionCountry sax-input" readonly="readonly" ondblclick="sax.selectRegionCountry()" /> </div>
|
||||
<div class="fixed"><button id="pbSelectRegion" class="sax-button" style="min-width:auto;margin-left:4px;padding:4px 6px" onclick="sax.selectRegionCountry()">@Localiser["label.select"]</button></div>
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* User province *@
|
||||
@*
|
||||
<div class="sax-form-control UserRegionIdProvince">
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="ifUserRegionCaptionProvince"><span>@Localiser["label.province"]</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="sax-control row">
|
||||
@Html.HiddenFor(model => model.UserRegionIdProvince, new { @id = "ifUserRegionIdProvince", @class = "UserRegionIdProvince" })
|
||||
<div class="col"><input type="text" id="ifUserRegionCaptionProvince" class="UserRegionCaptionProvince sax-input" readonly="readonly" ondblclick="sax.selectRegionProvince()" /> </div>
|
||||
<div class="fixed"><button id="pbSelectRegion" class="sax-button" style="min-width:auto;margin-left:4px;padding:4px 6px" onclick="sax.selectRegionProvince()">@Localiser["label.select"]</button></div>
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
*@
|
||||
|
||||
@* User roles *@
|
||||
<div class="sax-form-control UserRoles">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="lbUserRoles"><span>@Localiser["label.user.roles"]</span></label>
|
||||
</div>
|
||||
@@ -112,7 +156,7 @@
|
||||
@* User status *@
|
||||
<div class="sax-form-control UserStatus">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-3">
|
||||
<div class="sax-label">
|
||||
<label for="cbUserStatus"><span>@Localiser["label.status"]</span> <span class="required">*</span></label>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
@model Model_UsersOnline
|
||||
@inject SaxLocaliser Localiser
|
||||
@{
|
||||
/* Users Online - Index */
|
||||
ViewData["Title"] = "Users Online";
|
||||
}
|
||||
|
||||
<div class="sax-panel Users">
|
||||
|
||||
<script type="text/javascript">
|
||||
sax.lbl.refresh = '@(Localiser.GetJavascriptText("label.refresh"))';
|
||||
sax.lbl.edit = '@(Localiser.GetJavascriptText("label.edit"))';
|
||||
</script>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-5 row">
|
||||
|
||||
<div class="col">
|
||||
|
||||
@* Filter Panel *@
|
||||
@using (@Html.BeginForm(FormMethod.Post, new { @id = "frmUserFilter", @class = "sax-form", @onSubmit = "return false;" }))
|
||||
{
|
||||
|
||||
<div class="sax-panel-filter">
|
||||
@* Header - Page caption, paging controls, actions. *@
|
||||
<div class="sax-header row">
|
||||
<div class="col"><div class="sax-caption">@Localiser["label.users.online"]</div></div>
|
||||
<div class="fixed row">
|
||||
<div class="col">
|
||||
<partial name="~/Views/Common/ResultsPaging.cshtml" />
|
||||
</div>
|
||||
<div class="fixed">
|
||||
@* Burger menu *@
|
||||
<ul class="nav navbar-nav navbar-dark navbar-right sax-burger">
|
||||
<li class="dropdown-toggle caret-off">
|
||||
<a href="#" class="dropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="navbar-toggler-icon"></span></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right sax-dropdown-menu">@* Menu items will be inserted here. *@</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sax-content">
|
||||
@* User filter - email, name etc. *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["user.caption.user"]</div>
|
||||
<div class="col-sm-7">@Html.TextBoxFor(model => model.Filter.User, new { @id = "ifFilterUser", @class = "FilterUser", @maxlength = "32" })</div>
|
||||
</div>
|
||||
@* User sport *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["label.sport"]</div>
|
||||
<div class="col-sm-7">
|
||||
<div class="row">
|
||||
@Html.HiddenFor(model => model.Filter.UserSportId, new { @id = "", @class = "FilterUserSportId" })
|
||||
<div class="col"><input type="text" class="FilterUserSportCaption sax-input" readonly="readonly" ondblclick="sax.selectFilterSport()" /> </div>
|
||||
<div class="fixed row">
|
||||
<div class="sax-action" onclick="sax.selectFilterSport();"><img src="~/img/action/search24.png" alt="@(Localiser["label.search"])" title="@(Localiser["label.search"])" /></div>
|
||||
<div class="sax-action" onclick="sax.clearFilterSport();"><img src="~/img/action/delete24.png" alt="@(Localiser["label.clear"])" title="@(Localiser["label.clear"])" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@* User region *@
|
||||
<div class="row pb4">
|
||||
<div class="col-sm-5 sax-label text-left text-sm-right">@Localiser["label.region"]</div>
|
||||
<div class="col-sm-7">
|
||||
<div class="row">
|
||||
@Html.HiddenFor(model => model.Filter.UserRegionId, new { @id = "", @class = "FilterUserRegionId" })
|
||||
<div class="col"><input type="text" class="FilterUserRegionCaption sax-input" readonly="readonly" ondblclick="sax.selectFilterRegion()" /> </div>
|
||||
<div class="fixed row">
|
||||
<div class="sax-action" onclick="sax.selectFilterRegion();"><img src="~/img/action/search24.png" alt="@(Localiser["label.search"])" title="@(Localiser["label.search"])" /></div>
|
||||
<div class="sax-action" onclick="sax.clearFilterRegion();"><img src="~/img/action/delete24.png" alt="@(Localiser["label.clear"])" title="@(Localiser["label.clear"])" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Filter element templates *@
|
||||
<div class="sax-panel-item-template">
|
||||
@* Burger dropdown item template - ul is ignored *@
|
||||
<ul class="sax-dropdown-menu UserFilter">
|
||||
<li class="sax-dropdown-item sax-action"><div class="sax-label">XXX</div></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
@* Separate filter from results when alondside each other. *@
|
||||
<div class="fixed"><div class="d-none d-md-block" style="width:8px;"></div></div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md">
|
||||
|
||||
@* Results Panel *@
|
||||
<div class="sax-panel-results">
|
||||
<div class="sax-panel-messages"></div>
|
||||
<div class="sax-panel-item-list"></div>
|
||||
|
||||
@* Element templates *@
|
||||
<div class="sax-panel-item-template">
|
||||
|
||||
@* User item template *@
|
||||
<div class="sax-panel-item User">
|
||||
<div class="sax-header row">
|
||||
<div class="col">
|
||||
@* User email *@
|
||||
<div class="sax-caption"><div class="sax-action sax-item-update UserEmailAddress"></div></div>
|
||||
</div>
|
||||
<div class="fixed sax-actions">
|
||||
@* Burger menu *@
|
||||
<ul class="nav navbar-nav navbar-light navbar-right sax-burger">
|
||||
<li class="dropdown-toggle caret-off">
|
||||
<a href="#" class="dropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="navbar-toggler-icon"></span></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right sax-dropdown-menu">@* Menu items will be inserted here. *@</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sax-content">
|
||||
<div class="row">
|
||||
<div class="col-sm-4"><span class="UserDisplayName"></span></div>
|
||||
<div class="col-sm-4"><div class="UserLastLogin">Login: <span class="UserLastLoginAt"></span></div></div>
|
||||
<div class="col-sm-4"><div class="UserLastLogin">Online: <span class="UserLastOnlineAt"></span></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Burger dropdown item template - ul is ignored *@
|
||||
<ul class="sax-dropdown-menu User">
|
||||
<li class="sax-dropdown-item sax-action"><div class="sax-label">XXX</div></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<partial name="~/Views/Common/SelectItem.cshtml" />
|
||||
@@ -21,6 +21,10 @@
|
||||
{
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
sax.getTime = function ()
|
||||
{
|
||||
return (new Date()).getTime();
|
||||
}
|
||||
sax.zeroPad = function (num, count)
|
||||
{
|
||||
var val = num + '';
|
||||
@@ -353,37 +357,35 @@
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Session.
|
||||
sax.configureKeepLoggedIn = function ()
|
||||
sax.configureKeepLoggedIn = function (single)
|
||||
{
|
||||
sax.debug('KeepLoggedIn Configuring');
|
||||
setTimeout(sax.doKeepLoggedIn, Math.max(30000, sax.keepLoggedInDelay || 300000));
|
||||
let kli = sax.kli;
|
||||
if (!kli.timeout) kli.timeout = setTimeout(function () { sax.doKeepLoggedIn(single); }, Math.max(30000, kli.interval || 300000));
|
||||
}
|
||||
sax.doKeepLoggedIn = function ()
|
||||
sax.doKeepLoggedIn = function (single)
|
||||
{
|
||||
//sax.debug('KeepLoggedIn Calling');
|
||||
sax.debug('KeepLoggedIn Calling');
|
||||
let kli = sax.kli;
|
||||
delete kli.timeout;
|
||||
var onKeepLoggedIn = function (response)
|
||||
{
|
||||
sax.debug('KeepLoggedIn Responded', response);
|
||||
sax.configureKeepLoggedIn();
|
||||
kli.lastAt = sax.getTime();
|
||||
if (!single) sax.configureKeepLoggedIn();
|
||||
}
|
||||
sax.doAjaxRequest({ url: sax.url.base + 'Security/Ajax/KeepLoggedIn', formId: 'frmNavigate', noWaitIcon: true, callbackFn: onKeepLoggedIn }, 1000)
|
||||
}
|
||||
sax.configureSessionRefresh = function ()
|
||||
{
|
||||
//sax.debug('SessionRefresh Configuring');
|
||||
sax.debug('SessionRefresh Configuring');
|
||||
$(document).on('mousedown mousemove touchstart scroll keydown', sax.triggeRefreshSession);
|
||||
}
|
||||
sax.triggeRefreshSession = function ()
|
||||
{
|
||||
//sax.session = sax.session || { refresh: {} };
|
||||
let ssr = sax.session.refresh;
|
||||
win.clearTimeout(ssr.timeout);
|
||||
ssr.timeout = setTimeout(function () { sax.refreshSession(); }, 150000);
|
||||
}
|
||||
sax.refreshSession = function ()
|
||||
{
|
||||
//sax.debug('sax.refreshSession');
|
||||
sax.doKeepLoggedIn();
|
||||
if (sax.kli.timeout) return;
|
||||
sax.debug('SessionRefresh Triggering');
|
||||
sax.configureKeepLoggedIn(1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@@ -499,7 +501,7 @@
|
||||
$(function ()
|
||||
{
|
||||
$('.sax-button-cta,.sax-button-action,.sax-action-link,.sax-social-icon.sax-action').prop('tabindex', 0);
|
||||
if (sax.keepLoggedIn)
|
||||
if (sax.kli.active)
|
||||
sax.configureKeepLoggedIn();
|
||||
else if (!sax.awaitingLogin)
|
||||
sax.configureSessionRefresh();
|
||||
|
||||
@@ -61,7 +61,12 @@
|
||||
$('.UserTitle', $item).text(item.title);
|
||||
$('.UserFirstName', $item).text(item.firstName);
|
||||
$('.UserLastName', $item).text(item.lastName);
|
||||
$('.UserRegionNameCountry', $item).text(item.regionNameCountry);
|
||||
$('.UserRegionNameProvince', $item).text(item.regionNameProvince);
|
||||
$('.UserRoleCount', $item).text(item.userRoleCount);
|
||||
$('.UserRoles', $item).toggle(!!item.userRoleCount);
|
||||
$('.UserLastLoginAt', $item).text(item.lastLoginAt);
|
||||
$('.UserLastLogin', $item).toggle(!!item.lastLoginAt);
|
||||
$('.StatusDesc', $item).text(item.statusDesc).addClass('sax-status-' + item.statusCode.toLowerCase());
|
||||
$('.sax-caption .sax-action').toggleClass('sax-action', !item.deleted);
|
||||
let $mnu = $('ul.sax-dropdown-menu', $item);
|
||||
@@ -104,6 +109,7 @@
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Sports.
|
||||
sax.selectFilterSport = function ()
|
||||
{
|
||||
if (!sax.data.sports)
|
||||
@@ -111,9 +117,11 @@
|
||||
let handleFilterSportsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.sports)
|
||||
{
|
||||
sax.data.sports = response.sports;
|
||||
sax.showSelectFilterSport();
|
||||
}
|
||||
}
|
||||
sax.ajax.filterSports = sax.ajax.filterSports || { url: sax.url.base + 'Sport/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterSportsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.filterSports, 50);
|
||||
}
|
||||
@@ -125,33 +133,41 @@
|
||||
}
|
||||
sax.onFilterSportSelected = function (spt)
|
||||
{
|
||||
//sax.debug('onFilterSportSelected', sax.$frm.filter)
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserSportId', $frm).val(spt.id);
|
||||
$('.FilterUserSportCaption', $frm).val(spt.name);
|
||||
//sax.debug('onFilterSportSelected', $frm.filter)
|
||||
let $frmFlt = $frm.filter;
|
||||
$('.FilterUserSportId', $frmFlt).val(spt.id);
|
||||
$('.FilterUserSportCaption', $frmFlt).val(spt.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterSport = function ()
|
||||
{
|
||||
$('.FilterUserSportId,.FilterUserSportCaption', sax.$frm.filter).val('');
|
||||
$('.FilterUserSportId,.FilterUserSportCaption', $frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.selectFilterRegion = function ()
|
||||
// Regions.
|
||||
sax.populateRegions = function (fnCallback)
|
||||
{
|
||||
if (!sax.data.regions)
|
||||
{
|
||||
let handleFilterRegionsResponse = function (response)
|
||||
let handleRegionsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.regions)
|
||||
{
|
||||
sax.data.regions = response.regions;
|
||||
sax.showSelectFilterRegion();
|
||||
if (fnCallback) fnCallback();
|
||||
}
|
||||
sax.ajax.regions = sax.ajax.regions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterRegionsResponse };
|
||||
}
|
||||
sax.ajax.regions = sax.ajax.regions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleRegionsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.regions, 50);
|
||||
}
|
||||
else sax.showSelectFilterRegion();
|
||||
else if (fnCallback) fnCallback();
|
||||
}
|
||||
// Filter region.
|
||||
sax.selectFilterRegion = function ()
|
||||
{
|
||||
sax.populateRegions(sax.showSelectFilterRegion);
|
||||
}
|
||||
sax.showSelectFilterRegion = function ()
|
||||
{
|
||||
@@ -160,14 +176,58 @@
|
||||
sax.onFilterRegionSelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onFilterRegionSelected', rgn);
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserRegionId', $frm).val(rgn.id);
|
||||
$('.FilterUserRegionCaption', $frm).val(rgn.name);
|
||||
let $frmFlt = $frm.filter;
|
||||
$('.FilterUserRegionId', $frmFlt).val(rgn.id);
|
||||
$('.FilterUserRegionCaption', $frmFlt).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterRegion = function ()
|
||||
{
|
||||
$('.FilterUserRegionId,.FilterUserRegionCaption', sax.$frm.filter).val('');
|
||||
$('.FilterUserRegionId,.FilterUserRegionCaption', $frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
// Country region.
|
||||
sax.selectRegionCountry = function ()
|
||||
{
|
||||
sax.populateRegions(sax.showSelectRegionCountry);
|
||||
}
|
||||
sax.showSelectRegionCountry = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectRegionCountry, items: sax.data.regions, fnCallback: sax.onRegionCountrySelected });
|
||||
}
|
||||
sax.onRegionCountrySelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onRegionCountrySelected', rgn);
|
||||
let $frmUsr = $frm.user;
|
||||
$('.UserRegionIdCountry', $frmUsr).val(rgn.id);
|
||||
$('.UserRegionCaptionCountry', $frmUsr).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearRegionCountry = function ()
|
||||
{
|
||||
$('.UserRegionIdCountry,.UserRegionCaptionCountry', $frm.user).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
// Province region.
|
||||
sax.selectRegionProvince = function ()
|
||||
{
|
||||
sax.populateRegions(sax.showSelectRegionProvince);
|
||||
}
|
||||
sax.showSelectRegionProvince = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectRegionProvince, items: sax.data.regions, fnCallback: sax.onRegionProvinceSelected });
|
||||
}
|
||||
sax.onRegionProvinceSelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onRegionProvinceSelected', rgn);
|
||||
let $frmUsr = $frm.user;
|
||||
$('.UserRegionIdProvince', $frmUsr).val(rgn.id);
|
||||
$('.UserRegionCaptionProvince', $frmUsr).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearRegionProvince = function ()
|
||||
{
|
||||
$('.UserRegionIdProvince,.UserRegionCaptionProvince', $frm.user).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
@@ -203,14 +263,18 @@
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.createItem = function ()
|
||||
{
|
||||
sax.clearUserData();
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.createUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
sax.clearUserData = function ()
|
||||
{
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,.UserRoleCodes,input[type="text"],textarea,select', frm).val('');
|
||||
$('.UserAccountId,.UserRegionIdCountry,.UserRegionIdProvince,.UserRoleCodes,input[type="text"],textarea,select', frm).val('');
|
||||
$('.UserStatus', frm).val(sax.data.defaultStatusCode);
|
||||
sax.clearControlErrors();
|
||||
sax.userAccount = { userRoleCodes: [] };
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.createUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
@@ -223,16 +287,19 @@
|
||||
sax.onUpdateItem = function (response)
|
||||
{
|
||||
//sax.debug('onUpdateItem', response);
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,input[type="text"],textarea,select', frm).val('');
|
||||
sax.clearControlErrors();
|
||||
if (!response.success) return;
|
||||
sax.clearUserData();
|
||||
let item = sax.userAccount = response.user;
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId', frm).val(item.id);
|
||||
$('.UserEmailAddress', frm).val(item.emailAddress);
|
||||
$('.UserTitle', frm).val(item.title);
|
||||
$('.UserFirstName', frm).val(item.firstName);
|
||||
$('.UserLastName', frm).val(item.lastName);
|
||||
$('.UserRegionIdCountry', frm).val(item.regionIdCountry);
|
||||
$('.UserRegionCaptionCountry', frm).val(item.regionNameCountry);
|
||||
$('.UserRegionIdProvince', frm).val(item.regionIdProvince);
|
||||
$('.UserRegionCaptionProvince', frm).val(item.regionNameProvince);
|
||||
$('.UserRoles', frm).val(sax.getSelectedUserRoleDescs().join('\n'));
|
||||
$('#ifUserRoleCodes').val(item.userRoleCodes.join(sax.data.userRoleCodeDelim));
|
||||
$('.UserStatus', frm).val(item.statusCode);
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Admin - Users Online page scripts.
|
||||
*/
|
||||
|
||||
(function (win, doc, undef)
|
||||
{
|
||||
"use strict";
|
||||
let $pnl = sax.$pnl, $frm = sax.$frm, $dlg = sax.$dlg;
|
||||
sax.itemIdPrefix = 'Itm_';
|
||||
sax.userAccount = {};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.refreshResults = function (delay)
|
||||
{
|
||||
if (!sax.awaitingRefreshResponse)
|
||||
{
|
||||
$('.sax-burger', $pnl.filter).hide();
|
||||
var $items = $('.sax-panel-item-list', $pnl.results).fadeOut(200).empty();
|
||||
var $msgs = $('.sax-panel-messages', $pnl.results).hide().empty().append($('<div class="sax-message">' + sax.msg.dataQuerying + '</div>')).fadeIn(200);
|
||||
}
|
||||
sax.ajax.refreshResults = sax.ajax.refreshResults || { url: sax.url.base + 'UsersOnline/Ajax/GetList', formId: 'frmUserFilter', callbackFn: sax.doRefreshResults };
|
||||
sax.doAjaxRequest(sax.ajax.refreshResults, delay || 50);
|
||||
sax.awaitingRefreshResponse = true;
|
||||
}
|
||||
sax.doRefreshResults = function (response)
|
||||
{
|
||||
//sax.debug('doRefreshResults', response);
|
||||
delete sax.awaitingRefreshResponse;
|
||||
sax.refreshControlValues(response.controlValues);
|
||||
var $msgs = $('.sax-panel-messages', $pnl.results).hide().empty();
|
||||
var $items = $('.sax-panel-item-list', $pnl.results).hide().empty();
|
||||
sax.refreshPaging(response, '#frmUserFilter', sax.refreshResults);
|
||||
if (!response.success) return;
|
||||
// Reference data - Roles.
|
||||
if (response.userRoles && response.userRoles.length)
|
||||
sax.data.userRoles = response.userRoles;
|
||||
// Reference data - Statuses.
|
||||
if (response.defaultStatusCode) sax.data.defaultStatusCode = response.defaultStatusCode;
|
||||
if (response.statuses)
|
||||
sax.populateSelectCodeDesc('#cbUserStatus', response.statuses);
|
||||
// Menu.
|
||||
var $bgr = $('.sax-burger', $pnl.filter).hide();
|
||||
var $mnu = $('ul.sax-dropdown-menu', $bgr).empty();
|
||||
$mnu.append(sax.getFilterMenuOption(sax.lbl.refresh, function () { sax.refreshResults(); }));
|
||||
$bgr.toggle(!!$('.sax-dropdown-item', $mnu).length);
|
||||
// Items.
|
||||
var items = response.users;
|
||||
if (!items.length)
|
||||
return $msgs.append($('<div class="sax-message">' + sax.msg.dataNoneFound + '</div>')).fadeIn(500);
|
||||
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
||||
$items.append(sax.populateItem(sax.getItemTemplate(), items[itemIdx]));
|
||||
$items.fadeIn(50);
|
||||
}
|
||||
sax.populateItem = function ($item, item)
|
||||
{
|
||||
if (!item) return;
|
||||
$item.prop('id', sax.itemIdPrefix + item.id);
|
||||
$('.UserEmailAddress', $item).text(item.emailAddress);
|
||||
$('.UserDisplayName', $item).text(item.displayName);
|
||||
$('.UserLastLoginAt', $item).text(item.lastLoginAt);
|
||||
$('.UserLastOnlineAt', $item).text(item.onlineAt);
|
||||
$('.sax-caption .sax-action').toggleClass('sax-action', !item.deleted);
|
||||
let $mnu = $('ul.sax-dropdown-menu', $item);
|
||||
if (!item.deleted)
|
||||
{
|
||||
//$mnu.append(sax.getItemMenuOption(sax.lbl.edit, function () { sax.updateItem(item) }));
|
||||
//$('.sax-header .sax-action.sax-item-update', $item).off('click').on('click', function () { sax.updateItem(item) });
|
||||
//$item.off('dblclick').on('dblclick', function () { sax.updateItem(item) });
|
||||
}
|
||||
$('.sax-burger', $item).toggle(!!$('.sax-dropdown-item', $mnu).length);
|
||||
$('.sax-panel-messages', $pnl.results).hide().empty();
|
||||
return $item;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.getFilterDropdownTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-dropdown-menu.UserFilter li.sax-dropdown-item', $pnl.filter).clone();
|
||||
}
|
||||
sax.getItemTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-panel-item.User', $pnl.results).clone();
|
||||
}
|
||||
sax.getItemDropdownTemplate = function ()
|
||||
{
|
||||
return $('.sax-panel-item-template .sax-dropdown-menu.User li.sax-dropdown-item', $pnl.results).clone();
|
||||
}
|
||||
sax.getFilterMenuOption = function (lbl, fn)
|
||||
{
|
||||
return sax.getMenuOption(sax.getFilterDropdownTemplate(), lbl, fn);
|
||||
}
|
||||
sax.getItemMenuOption = function (lbl, fn)
|
||||
{
|
||||
return sax.getMenuOption(sax.getItemDropdownTemplate(), lbl, fn);
|
||||
}
|
||||
sax.getMenuOption = function ($opt, lbl, fn)
|
||||
{
|
||||
return $opt.find('div.sax-label').text(lbl).end().on('click', fn);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.selectFilterSport = function ()
|
||||
{
|
||||
if (!sax.data.sports)
|
||||
{
|
||||
let handleFilterSportsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.sports)
|
||||
sax.data.sports = response.sports;
|
||||
sax.showSelectFilterSport();
|
||||
}
|
||||
sax.ajax.filterSports = sax.ajax.filterSports || { url: sax.url.base + 'Sport/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterSportsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.filterSports, 50);
|
||||
}
|
||||
else sax.showSelectFilterSport();
|
||||
}
|
||||
sax.showSelectFilterSport = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectSport, items: sax.data.sports, fnCallback: sax.onFilterSportSelected });
|
||||
}
|
||||
sax.onFilterSportSelected = function (spt)
|
||||
{
|
||||
//sax.debug('onFilterSportSelected', sax.$frm.filter)
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserSportId', $frm).val(spt.id);
|
||||
$('.FilterUserSportCaption', $frm).val(spt.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterSport = function ()
|
||||
{
|
||||
$('.FilterUserSportId,.FilterUserSportCaption', sax.$frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.selectFilterRegion = function ()
|
||||
{
|
||||
if (!sax.data.regions)
|
||||
{
|
||||
let handleFilterRegionsResponse = function (response)
|
||||
{
|
||||
if (response && response.success && response.regions)
|
||||
sax.data.regions = response.regions;
|
||||
sax.showSelectFilterRegion();
|
||||
}
|
||||
sax.ajax.regions = sax.ajax.regions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleFilterRegionsResponse };
|
||||
sax.doAjaxRequest(sax.ajax.regions, 50);
|
||||
}
|
||||
else sax.showSelectFilterRegion();
|
||||
}
|
||||
sax.showSelectFilterRegion = function ()
|
||||
{
|
||||
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectFilterRegion, items: sax.data.regions, fnCallback: sax.onFilterRegionSelected });
|
||||
}
|
||||
sax.onFilterRegionSelected = function (rgn)
|
||||
{
|
||||
//sax.debug('onFilterRegionSelected', rgn);
|
||||
let $frm = sax.$frm.filter;
|
||||
$('.FilterUserRegionId', $frm).val(rgn.id);
|
||||
$('.FilterUserRegionCaption', $frm).val(rgn.name);
|
||||
sax.refreshResults();
|
||||
}
|
||||
sax.clearFilterRegion = function ()
|
||||
{
|
||||
$('.FilterUserRegionId,.FilterUserRegionCaption', sax.$frm.filter).val('');
|
||||
sax.refreshResults();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// User Roles.
|
||||
sax.selectUserRoles = function ()
|
||||
{
|
||||
//sax.debug('selectUserRoles');
|
||||
sax.selectUserRoleConfig = sax.selectUserRoleConfig || { caption: sax.dlg.title.selectUserRoles, width: 520, fnCallback: sax.updateUserRoles };
|
||||
sax.selectUserRoleConfig.codes = sax.data.userRoles;
|
||||
sax.selectUserRoleConfig.selectedCodes = sax.userAccount.userRoleCodes || [];
|
||||
sax.selectCode.fn.openSelectCode(sax.selectUserRoleConfig);
|
||||
}
|
||||
sax.updateUserRoles = function (userRoleCodes)
|
||||
{
|
||||
//sax.debug('updateUserRoles', userRoleCodes);
|
||||
sax.userAccount.userRoleCodes = userRoleCodes;
|
||||
$('#ifUserRoleCodes').val(userRoleCodes.join(sax.data.userRoleCodeDelim));
|
||||
$('#ifUserRoles').val(sax.getSelectedUserRoleDescs().join('\n'));
|
||||
}
|
||||
sax.getSelectedUserRoleDescs = function ()
|
||||
{
|
||||
let userRoles = [];
|
||||
sax.userAccount.userRoleCodes.forEach(function (value) { userRoles.push(sax.getUserRoleDesc(value)); })
|
||||
return userRoles.sortCI();
|
||||
}
|
||||
sax.getUserRoleDesc = function (roleCode)
|
||||
{
|
||||
let roleDesc = '';
|
||||
sax.data.userRoles.some(function (value) { if (value.code == roleCode) { roleDesc = value.desc; return true; } return false; })
|
||||
return roleDesc || roleCode;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.createItem = function ()
|
||||
{
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,.UserRoleCodes,input[type="text"],textarea,select', frm).val('');
|
||||
$('.UserStatus', frm).val(sax.data.defaultStatusCode);
|
||||
sax.clearControlErrors();
|
||||
sax.userAccount = { userRoleCodes: [] };
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.createUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.updateItem = function (item)
|
||||
{
|
||||
$('.UserAccountId', $frm.userId).val(item.id);
|
||||
sax.ajax.updateItem = sax.ajax.updateItem || { url: sax.url.base + 'User/Ajax/GetItem', formId: 'frmUserId', callbackFn: sax.onUpdateItem };
|
||||
sax.doAjaxRequest(sax.ajax.updateItem, 50);
|
||||
}
|
||||
sax.onUpdateItem = function (response)
|
||||
{
|
||||
//sax.debug('onUpdateItem', response);
|
||||
let frm = $frm.user;
|
||||
$('.UserAccountId,input[type="text"],textarea,select', frm).val('');
|
||||
sax.clearControlErrors();
|
||||
if (!response.success) return;
|
||||
let item = sax.userAccount = response.user;
|
||||
$('.UserAccountId', frm).val(item.id);
|
||||
$('.UserEmailAddress', frm).val(item.emailAddress);
|
||||
$('.UserTitle', frm).val(item.title);
|
||||
$('.UserFirstName', frm).val(item.firstName);
|
||||
$('.UserLastName', frm).val(item.lastName);
|
||||
$('.UserRoles', frm).val(sax.getSelectedUserRoleDescs().join('\n'));
|
||||
$('#ifUserRoleCodes').val(item.userRoleCodes.join(sax.data.userRoleCodeDelim));
|
||||
$('.UserStatus', frm).val(item.statusCode);
|
||||
$dlg.user.dialog('option', 'title', sax.dlg.title.updateUser);
|
||||
sax.openDialog($dlg.user, 600, 480);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.storeItem = function ()
|
||||
{
|
||||
sax.ajax.storeItem = sax.ajax.storeItem || { url: sax.url.base + 'User/Ajax/StoreItem', formId: 'frmUser', callbackFn: sax.onStoreItem };
|
||||
sax.doAjaxRequest(sax.ajax.storeItem, 50);
|
||||
}
|
||||
sax.onStoreItem = function (response)
|
||||
{
|
||||
//sax.debug('onStoreItem', response);
|
||||
sax.refreshControlValues(response.controlValues);
|
||||
if (!response.success) return;
|
||||
$dlg.user.dialog('close');
|
||||
|
||||
var item = response.user;
|
||||
var $item = $('#' + sax.itemIdPrefix + item.id);
|
||||
if (!$item.length)
|
||||
{
|
||||
$item = sax.getItemTemplate();
|
||||
$('.sax-panel-item-list', $pnl.results).prepend($item).show();
|
||||
}
|
||||
$item.replaceWith(sax.populateItem(sax.getItemTemplate(), item));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sax.userEmails = function (item)
|
||||
{
|
||||
sax.debug('userEmails', item);
|
||||
let frm = $frm.emailsl
|
||||
$('.UserAccountId', frm).val(item.id);
|
||||
$('.UserEmailAddress', frm).val(item.emailAddress);
|
||||
$('.UserDisplayName', frm).val(item.displayName);
|
||||
$('.RequestPasswordAdminOption', frm).toggle(item.systemAdmin);
|
||||
$('input[type="checkbox"]', frm).prop('checked', false);
|
||||
$dlg.emails.dialog('option', { 'title': sax.dlg.title.selectUserEmails });
|
||||
sax.openDialog($dlg.emails, 600, 360);
|
||||
}
|
||||
sax.sendUserEmails = function ()
|
||||
{
|
||||
sax.ajax.sendEmails = sax.ajax.sendEmails || { url: sax.url.base + 'User/Ajax/SendEmails', formId: 'frmUserEmails', callbackFn: sax.onUserEmails };
|
||||
sax.doAjaxRequest(sax.ajax.sendEmails, 50);
|
||||
}
|
||||
sax.onUserEmails = function (response)
|
||||
{
|
||||
if (!response || !response.success) return;
|
||||
$dlg.emails.dialog('close');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
$(function ()
|
||||
{
|
||||
$pnl.users = $('.sax-panel.Users');
|
||||
$pnl.filter = $('.sax-panel-filter', $pnl.users);
|
||||
$pnl.results = $('.sax-panel-results', $pnl.users);
|
||||
|
||||
$frm.filter = $('#frmUserFilter');
|
||||
$('.FilterUser', $frm.filter).on('input', function () { sax.refreshResults(250); });
|
||||
$('.FilterUserStatusCategory', $frm.filter).on('change', function () { sax.refreshResults(50); });
|
||||
$frm.userId = $('#frmUserId');
|
||||
$frm.user = $('#frmUser');
|
||||
$('.sax-input, .sax-textarea', $frm.user).on('input', function () { sax.clearControlError(this); });
|
||||
$('.sax-select', $frm.user).on('change', function () { sax.clearControlError(this); });
|
||||
$frm.emails = $('#frmUserEmails');
|
||||
|
||||
var opt = sax.dlgOpts();
|
||||
opt.buttons[sax.dlg.btn.ok] = function () { sax.storeItem(); };
|
||||
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
||||
$dlg.user = $('#dlgUser').dialog(opt);
|
||||
|
||||
opt = sax.dlgOpts();
|
||||
opt.buttons[sax.dlg.btn.ok] = function () { sax.sendUserEmails(); };
|
||||
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
||||
$dlg.emails = $('#dlgUserEmails').dialog(opt);
|
||||
|
||||
setTimeout(sax.refreshResults, 250);
|
||||
});
|
||||
|
||||
}(window, window.document));
|
||||
|
||||
/* The End */
|
||||
@@ -37,6 +37,20 @@ namespace Saxonite.Net.Core.Web.Online.Consoles
|
||||
return dataCacheConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session Data console.
|
||||
private readonly Dictionary<ushort, SaxSessionDataConsole_Online> sessionDataConsoles = new Dictionary<ushort, SaxSessionDataConsole_Online>();
|
||||
public override SaxSessionDataConsole GetSessionDataConsole(SaxSessionContext sessionContext)
|
||||
{
|
||||
if (sessionContext == null) throw new NotSupportedException(GetType().Name + ".GetSessionDataConsole Session Context must be specified");
|
||||
SaxSessionDataConsole_Online sessionDataConsole = sessionDataConsoles.GetValueOrDefault(sessionContext.Index, null);
|
||||
if (sessionDataConsole == null)
|
||||
{
|
||||
sessionDataConsole = sessionDataConsoles[sessionContext.Index] = new SaxSessionDataConsole_Online(sessionContext);
|
||||
}
|
||||
return sessionDataConsole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Activity console.
|
||||
public override SaxActivityConsole CreateActivityConsole(SaxSessionContext sessionContext)
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Saxonite.Net.Core.Web.Online.Consoles
|
||||
private System.Timers.Timer refreshTimer;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SaxDataCacheConsole_Online(SaxSessionContext sessionContext) :
|
||||
base(sessionContext)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
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.Net.Core.Web.Base.Consoles;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using Saxonite.Net.Standard.Base.Consoles;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Online.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class SaxSessionDataConsole_Online : SaxSessionDataConsole_Web
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private static SaxSessionDataConsole_Online console = null;
|
||||
private System.Timers.Timer commitTimer = null;
|
||||
/// <summary>Latest time that a user was active on the online system - awaiting commit to the database.</summary>
|
||||
private SacsQueueDictionary<SysId, SaxUserOnline.DataProperties> usersActiveAt = new SacsQueueDictionary<SysId, SaxUserOnline.DataProperties>();
|
||||
private DateTime lastDataCommit = DateTime.MinValue;
|
||||
private int commitBatchSize = 32;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SaxSessionDataConsole_Online(SaxSessionContext sessionContext) :
|
||||
base(sessionContext)
|
||||
{
|
||||
String fn = GetType().Name + ".CTR";
|
||||
if (console != null)
|
||||
{
|
||||
SaLogger.Info(fn + " Instance already exists");
|
||||
throw new InvalidOperationException(GetType().Name + " - instance already exists.");
|
||||
}
|
||||
console = this;
|
||||
SaLogger.Info(fn + "");
|
||||
|
||||
// Initilise commit timer.
|
||||
commitTimer = new System.Timers.Timer(Math.Max(2, Sax.Config.Online.DataCache.RefreshIntervalSecs.Initial) * 1000);
|
||||
commitTimer.Elapsed += CommitTimer_Elapsed;
|
||||
commitTimer.Start();
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (Object.ReferenceEquals(console, this))
|
||||
console = null;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Record User Online activity.
|
||||
//-------------------------------------------------------------------
|
||||
public override bool RecordUserActive(SysId userAccountId, DateTime activeAt)
|
||||
{
|
||||
if (!SysId.IsValid(userAccountId) || !DateUtil.IsValid(activeAt)) return false;
|
||||
usersActiveAt.SetEntry(userAccountId, new SaxUserOnline.DataProperties() { UserAccountId = userAccountId, OnlineAt = activeAt });
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Commit User Online activity.
|
||||
//-------------------------------------------------------------------
|
||||
public override DateTime LastDataCommit()
|
||||
{
|
||||
lock (usersActiveAt)
|
||||
return lastDataCommit;
|
||||
}
|
||||
private void CommitTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
commitTimer.Stop();
|
||||
CommitData();
|
||||
}
|
||||
private void CommitData()
|
||||
{
|
||||
String fn = GetType().Name + ".CommitData";
|
||||
commitTimer.Stop();
|
||||
|
||||
// Extract data to be committed.
|
||||
List<KeyValuePair<SysId, SaxUserOnline.DataProperties>> usersActiveAtToCommit = usersActiveAt.RemoveTopEntries(commitBatchSize);
|
||||
|
||||
// Reset the timer.
|
||||
int intervalSecs = Sax.Config.Online.Session.DataCommit.IntervalSecs.NoDataWaiting;
|
||||
if (usersActiveAt.Count > 0)
|
||||
{
|
||||
// Additional Data is waiting to be committed.
|
||||
intervalSecs = Sax.Config.Online.Session.DataCommit.IntervalSecs.DataWaiting;
|
||||
}
|
||||
commitTimer.Interval = Math.Max(1, intervalSecs) * 1000;
|
||||
commitTimer.Start();
|
||||
|
||||
// Commit the data.
|
||||
if (usersActiveAtToCommit.Count > 0)
|
||||
{
|
||||
if (SacsSystem.DebugMode)
|
||||
SaLogger.Info(fn + " Entries to commit: " + usersActiveAtToCommit.Count);
|
||||
Internals.AccountMgr.CommitUsersOnline(usersActiveAtToCommit.Select(ItemId => ItemId.Value).ToList());
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -48,9 +48,9 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
[HttpPost]
|
||||
[Route("Search/Ajax/Organisations")]
|
||||
[Route("Search/Ajax/GetOrganisations")]
|
||||
public IActionResult GetProfileOrganisations(Model_Search_Organisations model)
|
||||
public IActionResult Ajax_GetOrganisations(Model_Search_Organisations model)
|
||||
{
|
||||
String fn = GetType().Name + ".GetProfileOrganisations";
|
||||
String fn = GetType().Name + ".Ajax_GetOrganisations";
|
||||
AjaxResponse_Search_Organisations responseData = new AjaxResponse_Search_Organisations(model);
|
||||
String messageTitle = Localiser["organisation.caption.organisations"];
|
||||
|
||||
@@ -68,6 +68,8 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
prmOrganisation.OrganisationFilter = model.Filter.Organisation;
|
||||
prmOrganisation.OrganisationType = model.FilterOrganisationType;
|
||||
prmOrganisation.OrganisationCategory = model.FilterOrganisationCategory;
|
||||
prmOrganisation.OrganisationCategoriesExcluded.Add(Sax.OrganisationCategory.Partner);
|
||||
prmOrganisation.OrganisationCategoriesExcluded.Add(Sax.OrganisationCategory.Other);
|
||||
if (SysId.IsValid(model.FilterSportId))
|
||||
prmOrganisation.SportIdsIncluded.Add(model.FilterSportId);
|
||||
if (SysId.IsValid(model.FilterRegionId))
|
||||
@@ -151,9 +153,9 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
[HttpPost]
|
||||
[Route("Search/Ajax/Organisation")]
|
||||
[Route("Search/Ajax/GetOrganisation")]
|
||||
public IActionResult GetProfileOrganisation(Model_Search_Organisations model)
|
||||
public IActionResult Ajax_GetOrganisation(Model_Search_Organisations model)
|
||||
{
|
||||
String fn = GetType().Name + ".GetProfileOrganisation";
|
||||
String fn = GetType().Name + ".Ajax_GetOrganisation";
|
||||
AjaxResponse_Search_Organisation responseData = new AjaxResponse_Search_Organisation(model);
|
||||
String messageTitle = Localiser["label.organisation"];
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
[HttpPost]
|
||||
[Route("Search/Ajax/Users")]
|
||||
[Route("Search/Ajax/GetUsers")]
|
||||
public IActionResult GetProfileUsers(Model_Search_Users model)
|
||||
public IActionResult Ajax_GetUsers(Model_Search_Users model)
|
||||
{
|
||||
String fn = GetType().Name + ".GetProfileUsers";
|
||||
String fn = GetType().Name + ".Ajax_GetUsers";
|
||||
AjaxResponse_Search_Users responseData = new AjaxResponse_Search_Users(model);
|
||||
String messageTitle = Localiser["label.users"];
|
||||
|
||||
@@ -54,18 +54,19 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
if (!ValidUserSession) return GetAjaxResult_InvalidSession(responseData);
|
||||
RefreshModel(model);
|
||||
|
||||
// Ensure data is paged to avoid leaking large volumes.
|
||||
model.Paging.PageNo = Math.Max(1, model.Paging.PageNo);
|
||||
model.Paging.PageLength = Math.Max(Math.Min(Sax.Config.Online.Search.Users.PageLengthMax, model.Paging.PageLength), (ushort)1);
|
||||
|
||||
// Ensure filter has something to restrict the list.
|
||||
// ToDo May be able to show some results, such as friends when no filter provided.
|
||||
if (StringUtil.IsEmpty(StringUtil.TrimAll(model.Filter.User)))
|
||||
{
|
||||
responseData.SetPaging(model);
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
// Ensure data is paged to avoid leaking large volumes.
|
||||
model.Paging.PageNo = Math.Max(1, model.Paging.PageNo);
|
||||
model.Paging.PageLength = Math.Max(Math.Min(Sax.Config.Online.Search.Users.PageLengthMax, model.Paging.PageLength), (ushort)1);
|
||||
|
||||
// Query users that user is a member of.
|
||||
SaxUserAccount.Params prmUserAccount = new SaxUserAccount.Params();
|
||||
prmUserAccount.UserFilter = model.Filter.User;
|
||||
@@ -142,9 +143,9 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
[HttpPost]
|
||||
[Route("Search/Ajax/User")]
|
||||
[Route("Search/Ajax/GetUser")]
|
||||
public IActionResult GetProfileUser(Model_Search_Users model)
|
||||
public IActionResult Ajax_GetUser(Model_Search_Users model)
|
||||
{
|
||||
String fn = GetType().Name + ".GetProfileUser";
|
||||
String fn = GetType().Name + ".Ajax_GetUser";
|
||||
AjaxResponse_Search_User responseData = new AjaxResponse_Search_User(model);
|
||||
String messageTitle = Localiser["label.user"];
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace Saxonite.Net.Core.Web.Online.Controllers
|
||||
public ActionResult Ajax_KeepLoggedIn(Model_Security model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_KeepLoggedIn";
|
||||
if (DebugMode) SaLogger.Debug(fn);
|
||||
AjaxResponse_KeepLoggedIn responseData = new AjaxResponse_KeepLoggedIn();
|
||||
|
||||
// Validate session and referrer.
|
||||
|
||||
@@ -6,6 +6,7 @@ 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.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -130,7 +131,7 @@ namespace Saxonite.Net.Core.Web.Online.Models
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
||||
else if (!DateUtil.IsValid(publishedOn))
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
else if (publishedOn.CompareTo(DateTime.Today) > 0)
|
||||
else if (publishedOn.CompareTo(DateUtil.IncrementDate(DateTime.Today, Sax.Config.Online.Articles.PublishMaxDaysAhead)) > 0)
|
||||
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="jQuery.UI.Combined" Version="1.12.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.16" />
|
||||
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<div class="sax-panel Articles">
|
||||
|
||||
<script type="text/javascript">
|
||||
sax.maxPublishDaysAhead = '@(Sax.Config.Online.Articles.PublishMaxDaysAhead)';
|
||||
sax.lbl.edit = '@(Localiser.GetJavascriptText("label.edit"))';
|
||||
sax.lbl.remove = '@(Localiser.GetJavascriptText("label.remove"))';
|
||||
</script>
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<div class="col">@Html.TextBoxFor(model => model.ArticlePublishOn, new { @id = "ifArticlePublishOn", @class = "sax-input sax-calendar ArticlePublishOn", @readonly = "readonly" })</div>
|
||||
</div>
|
||||
<div class="row ArticlePublished">
|
||||
<div class="col"><div class="pl16">@Localiser["label.published"]: <span class="ArticlePublishedOn"></span></div></div>
|
||||
<div class="col"><div class="">@Localiser["label.published"]: <span class="ArticlePublishedOn"></span></div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<label for=""><span>@Localiser["label.category"]</span><span class="required"> *</span></label>
|
||||
</div>
|
||||
<div class="sax-control">
|
||||
@Html.DropDownList("", Model.OrganisationCategoriesForSelect, Localiser["label.select"], new { @id = "", @name = "Organisation.Category", @class = "OrganisationCategory sax-select" })
|
||||
@Html.DropDownList("", Model.OrganisationCategoriesForSelect, Localiser["label.select"] + ":", new { @id = "", @name = "Organisation.Category", @class = "OrganisationCategory sax-select" })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
@@ -48,7 +48,7 @@
|
||||
<label for=""><span>@Localiser["label.type"]</span><span class="required"> *</span></label>
|
||||
</div>
|
||||
<div class="sax-control">
|
||||
@Html.DropDownList("", Model.OrganisationTypesForSelect, Localiser["label.select"], new { @id = "", @name = "Organisation.Type", @class = "OrganisationType sax-select" })
|
||||
@Html.DropDownList("", Model.OrganisationTypesForSelect, Localiser["label.select"] + ":", new { @id = "", @name = "Organisation.Type", @class = "OrganisationType sax-select" })
|
||||
</div>
|
||||
<div class="sax-message"></div>
|
||||
</div>
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
@* Results paging *@
|
||||
<div class="sax-results-paging hidden">
|
||||
|
||||
@Html.HiddenFor(model => model.Paging.PageNo, new { @id = "", @class = "PagingPageNo" })
|
||||
@Html.HiddenFor(model => model.Paging.PageLength, new { @id = "", @class = "PagingPageLength" })
|
||||
@Html.HiddenFor(model => model.Paging.PageNoValue, new { @id = "", @class = "PagingPageNo" })
|
||||
@Html.HiddenFor(model => model.Paging.PageLengthValue, new { @id = "", @class = "PagingPageLength" })
|
||||
|
||||
<div class="iblock sax-action sax-paging-first"><img src="~/img/action/first24.png" alt="@(Localiser["label.first"])" title="@(Localiser["label.first"])" /></div>
|
||||
<div class="iblock sax-action sax-paging-prev"><img src="~/img/action/prev24.png" alt="@(Localiser["label.previous"])" title="@(Localiser["label.previous"])" /></div>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
@* Organisation type *@
|
||||
<div class="sax-control row">
|
||||
<div class="col-sm-4"><div class="sax-label text-left text-sm-right">@Localiser["label.type"]</div></div>
|
||||
<div class="col-sm-4"><div class="sax-label text-left text-sm-right">@Localiser["label.category"]</div></div>
|
||||
<div class="col-sm">
|
||||
@Html.DropDownListFor(model => model.Filter.Category, Model.OrganisationCategoriesForSelect, Localiser["label.any"], new { @id = "", @class = "FilterCategory sax-select" })
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
|
||||
<div class="spacer"></div>
|
||||
|
||||
<div class="row UserName">
|
||||
<div class="col-sm-5"><div class="sax-label text-sm-right">@Localiser["label.name"]</div></div>
|
||||
<div class="col-sm"><div class="sax-value"></div></div>
|
||||
</div>
|
||||
|
||||
<div class="row UserLocation">
|
||||
<div class="col-sm-5"><div class="sax-label text-sm-right">@Localiser["label.location"]</div></div>
|
||||
<div class="col-sm"><div class="sax-value"></div></div>
|
||||
|
||||
@@ -55,8 +55,7 @@
|
||||
|
||||
@* Scripts *@
|
||||
<script>
|
||||
var sax = sax || {
|
||||
page: {}, url: {}, links: {}, data: {}, form: {}, mdl: {}, ajax: {}, msg: {}, lbl: {}, dlg: { title: {}, btn: {} }, $frm: {}, $dlg: {}, $pnl: {} };
|
||||
var sax = sax || { page: {}, url: {}, links: {}, data: {}, form: {}, mdl: {}, ajax: {}, msg: {}, lbl: {}, dlg: { title: {}, btn: {} }, $frm: {}, $dlg: {}, $pnl: {}, session: {}, kli: {} };
|
||||
sax.url.base = '@Model.RedirectLocation.Base';
|
||||
sax.url.home = '@Model.RedirectLocation.Home';
|
||||
sax.url.sessionExpired = '@Model.RedirectLocation.Home_SessionExpired';
|
||||
@@ -87,10 +86,10 @@
|
||||
sax.msg.dataQuerying = '@Localiser.GetJavascriptText("msg.data.querying")';
|
||||
sax.msg.dataNoneFound = '@Localiser.GetJavascriptText("msg.data.noneFound")';
|
||||
sax.maxProfileImageSize = 2*10**6;
|
||||
sax.sessionCookieName = '@Model.SessionCookieName';
|
||||
sax.session.cookieName = '@Model.SessionCookieName';
|
||||
sax.awaitingLogin = @awaitingLogin;
|
||||
sax.keepLoggedIn = @keepLoggedIn;
|
||||
sax.keepLoggedInDelay = @(Sax.Config.Admin.Session.Cookie.KeepLoggedInTimeoutMillis);
|
||||
sax.kli.active = @keepLoggedIn;
|
||||
sax.kli.interval = @(Sax.Config.Admin.Session.Cookie.KeepLoggedInTimeoutMillis);
|
||||
sax.debugMode = @debug;
|
||||
</script>
|
||||
|
||||
|
||||
@@ -142,6 +142,8 @@
|
||||
$('#ifArticleOrganisation', $frmA).val($('#ifFilterOrganisation', $frmF).val());
|
||||
$('.sax-form-control.ArticleOrganisation', $frmA).toggle(!!orgId);
|
||||
$('#chkArticlePublish', $frmA).prop("checked", false);
|
||||
$('div.ArticlePublish', $frmA).show();
|
||||
$('div.ArticlePublished', $frmA).hide();
|
||||
$('.sax-input.sax-calendar.ArticlePublishOn', $frmA).datepicker('setDate', 'today');
|
||||
sax.clearControlErrors();
|
||||
}
|
||||
@@ -462,7 +464,7 @@
|
||||
});
|
||||
$frm.articleId = $('#frmArticleId');
|
||||
$frm.article = $('#frmArticle');
|
||||
$('.sax-input', $frm.article).on('input', function () { sax.clearControlError(this); });
|
||||
$('.sax-input,.sax-textarea', $frm.article).on('input', function () { sax.clearControlError(this); });
|
||||
|
||||
var opt = sax.dlgOpts();
|
||||
opt.buttons[sax.dlg.btn.cancel] = { text: sax.dlg.btn.cancel, class: "floatr", click: function () { $(this).dialog('close'); } };
|
||||
@@ -473,7 +475,7 @@
|
||||
|
||||
ac.$content = $('.sax-article-panel.sax-article-content');
|
||||
ac.$segList = $('.sax-article-segment-list', ac.$content);
|
||||
sax.initCalendars('.sax-input.sax-calendar').datepicker('option', { maxDate: '+00' });
|
||||
sax.initCalendars('.sax-input.sax-calendar').datepicker('option', { maxDate: '+' + (sax.maxPublishDaysAhead||'0') });
|
||||
|
||||
var opt = sax.dlgOpts();
|
||||
opt.buttons[sax.dlg.btn.ok] = function () { sax.uploadArticleImage(); };
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
{
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
sax.getTime = function ()
|
||||
{
|
||||
return (new Date()).getTime();
|
||||
}
|
||||
sax.zeroPad = function (num, count)
|
||||
{
|
||||
var val = num + '';
|
||||
@@ -375,39 +379,26 @@
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Session.
|
||||
sax.configureKeepLoggedIn = function ()
|
||||
sax.configureKeepLoggedIn = function (single)
|
||||
{
|
||||
//sax.debug('KeepLoggedIn Configuring');
|
||||
setTimeout(sax.doKeepLoggedIn, Math.max(30000, sax.keepLoggedInDelay || 300000));
|
||||
let kli = sax.kli;
|
||||
if (!kli.timeout) kli.timeout = setTimeout(function () { sax.doKeepLoggedIn(single); }, Math.max(30000, kli.interval || 300000));
|
||||
}
|
||||
sax.doKeepLoggedIn = function ()
|
||||
sax.doKeepLoggedIn = function (single)
|
||||
{
|
||||
//sax.debug('KeepLoggedIn Calling');
|
||||
var onKeepLoggedIn = function (response)
|
||||
{
|
||||
//sax.debug('KeepLoggedIn Responded', response);
|
||||
sax.configureKeepLoggedIn();
|
||||
}
|
||||
sax.doAjaxRequest({ url: sax.url.base + 'Security/Ajax/KeepLoggedIn', formId: 'frmNavigate', noWaitIcon: true, callbackFn: onKeepLoggedIn }, 1000)
|
||||
let kli = sax.kli;
|
||||
delete kli.timeout;
|
||||
sax.doAjaxRequest({ url: sax.url.base + 'Security/Ajax/KeepLoggedIn', formId: 'frmNavigate', noWaitIcon: true, callbackFn: function (response) { kli.lastAt = sax.getTime(); if (!single) sax.configureKeepLoggedIn(); } }, 1000)
|
||||
}
|
||||
sax.configureSessionRefresh = function ()
|
||||
{
|
||||
//sax.debug('SessionRefresh Configuring');
|
||||
$(document).on('mousedown mousemove touchstart scroll keydown', sax.triggeRefreshSession);
|
||||
}
|
||||
sax.triggeRefreshSession = function ()
|
||||
{
|
||||
sax.session = sax.session || { refresh: {} };
|
||||
let ssr = sax.session.refresh;
|
||||
win.clearTimeout(ssr.timeout);
|
||||
ssr.timeout = setTimeout(function () { sax.refreshSession(); }, 150000);
|
||||
if (sax.kli.timeout) return;
|
||||
sax.configureKeepLoggedIn(1);
|
||||
}
|
||||
sax.refreshSession = function ()
|
||||
{
|
||||
//sax.debug('sax.refreshSession');
|
||||
sax.doKeepLoggedIn();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Data entry.
|
||||
sax.clearControlErrors = function (context)
|
||||
@@ -520,7 +511,7 @@
|
||||
$(function ()
|
||||
{
|
||||
$('.sax-button-cta,.sax-button-action,.sax-action-link,.sax-social-icon.sax-action').prop('tabindex', 0);
|
||||
if (sax.keepLoggedIn)
|
||||
if (sax.kli.active)
|
||||
sax.configureKeepLoggedIn();
|
||||
else if (!sax.awaitingLogin)
|
||||
sax.configureSessionRefresh();
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
if (!response.success) return;
|
||||
let dlg = $dlg.usr;
|
||||
let item = su.data.user = response.user;
|
||||
$('.UserName', dlg).val(item.name);
|
||||
$('.UserName', dlg).find('.sax-value').text(item.name);
|
||||
$('.UserLocation', dlg).toggle(!!item.location).find('.sax-value').text(item.location);
|
||||
sax.clearControlErrors();
|
||||
$dlg.usr.dialog('option', 'title', item.name || sax.dlg.title.user);
|
||||
|
||||
@@ -53,7 +53,16 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
public static String Name { get; } = "Saxonite.Online.Session";
|
||||
public static bool HttpOnly { get; } = true;
|
||||
public static TimeSpan IdleTimeout { get; } = SacsSystem.DebugMode ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(60);
|
||||
public static long RememberMeTimeoutMilis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(2) : TimeSpan.FromMinutes(10)).TotalMilliseconds;
|
||||
public static long RememberMeTimeoutMilis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(1) : TimeSpan.FromMinutes(15)).TotalMilliseconds;
|
||||
}
|
||||
public static class DataCommit
|
||||
{
|
||||
public static class IntervalSecs
|
||||
{
|
||||
public static int Initial { get; } = SacsSystem.DebugMode ? 10 : 10;
|
||||
public static int DataWaiting { get; } = SacsSystem.DebugMode ? 1 : 2;
|
||||
public static int NoDataWaiting { get; } = SacsSystem.DebugMode ? 5 : 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class DataCache
|
||||
@@ -61,19 +70,23 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
public static class RefreshIntervalSecs
|
||||
{
|
||||
public static int Initial { get; } = SacsSystem.DebugMode ? 2 : 5;
|
||||
public static int Periodic { get; } = SacsSystem.DebugMode ? 60 : 1800;
|
||||
public static int Periodic { get; } = SacsSystem.DebugMode ? 120 : 1800;
|
||||
}
|
||||
}
|
||||
public static class Articles
|
||||
{
|
||||
public static ushort PublishMaxDaysAhead { get; } = 14;
|
||||
}
|
||||
public static class Search
|
||||
{
|
||||
public static class Users
|
||||
{
|
||||
public static ushort PageLengthDefault { get; } = 12;
|
||||
public static ushort PageLengthDefault { get; } = 8;
|
||||
public static ushort PageLengthMax { get; } = 20;
|
||||
}
|
||||
public static class Organisations
|
||||
{
|
||||
public static ushort PageLengthDefault { get; } = 12;
|
||||
public static ushort PageLengthDefault { get; } = 8;
|
||||
public static ushort PageLengthMax { get; } = 20;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +101,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
public static String Name { get; } = "Saxonite.Admin.Session";
|
||||
public static bool HttpOnly { get; } = true;
|
||||
public static TimeSpan IdleTimeout { get; } = SacsSystem.DebugMode ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(15);
|
||||
public static long KeepLoggedInTimeoutMillis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(2) : TimeSpan.FromMinutes(10)).TotalMilliseconds;
|
||||
public static long KeepLoggedInTimeoutMillis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(1) : TimeSpan.FromMinutes(5)).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
//-------------------------------------------------------------------
|
||||
public static class Version
|
||||
{
|
||||
private static String version { get; } = "1.2.2";
|
||||
private static String version { get; } = "1.2.3.1";
|
||||
// Retrieve version.
|
||||
public static String GetFullVersion () { return version; }
|
||||
public static String GetAppVersion ()
|
||||
@@ -40,6 +40,11 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
//-------------------------------------------------------------------
|
||||
// Version history.
|
||||
//-------------------------------------------------------------------
|
||||
// 1.2.3 16-Feb-2022 User online activity.
|
||||
// - Record user last online.
|
||||
// - Online Organisation category select - remove Partner/Other.
|
||||
// - Online Article edit - clear publication on add, future publication.
|
||||
// - Admin Users - region selection.
|
||||
// 1.2.2 8-Dec-2021 Online Activities.
|
||||
// - Organisation Events.
|
||||
// 1.2.1 20-Nov-2021 Online Profile.
|
||||
|
||||
@@ -218,6 +218,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
/* Do not change the names/codes - tied to database. */
|
||||
Association,
|
||||
Club,
|
||||
Society,
|
||||
Education,
|
||||
Syndicate,
|
||||
/// <summary>Commercial partner</summary>
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Base.App
|
||||
{
|
||||
@@ -29,6 +29,7 @@ namespace Saxonite.Base.App
|
||||
Sport,
|
||||
UserAccount,
|
||||
UserActivity,
|
||||
UserOnline,
|
||||
UserOrganisation,
|
||||
UserRole,
|
||||
UserSession,
|
||||
@@ -280,6 +281,8 @@ namespace Saxonite.Base.App
|
||||
UserActivity_UpdateOn,
|
||||
UserActivity_UpdateBy,
|
||||
UserActivity_UpdateHost,
|
||||
UserOnline_UserAccountId,
|
||||
UserOnline_OnlineAt,
|
||||
UserOrganisation_Id,
|
||||
UserOrganisation_UserAccountId,
|
||||
UserOrganisation_OrganisationId,
|
||||
@@ -356,8 +359,8 @@ namespace Saxonite.Base.App
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private static readonly int tableCount = 17;
|
||||
private static readonly int columnCount = 311;
|
||||
private static readonly int tableCount = 18;
|
||||
private static readonly int columnCount = 313;
|
||||
private static ulong maxTextLen = 0;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -515,6 +518,7 @@ namespace Saxonite.Base.App
|
||||
"Sport",
|
||||
"UserAccount",
|
||||
"UserActivity",
|
||||
"UserOnline",
|
||||
"UserOrganisation",
|
||||
"UserRole",
|
||||
"UserSession",
|
||||
@@ -785,24 +789,14 @@ namespace Saxonite.Base.App
|
||||
new ColumnDfn(12,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(12,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(12,"UpdateHost",0,12,false,100),
|
||||
new ColumnDfn(13,"Id",5,-5,true,19),
|
||||
new ColumnDfn(13,"UserAccountId",4,4,false,10),
|
||||
new ColumnDfn(13,"OrganisationId",4,4,false,10),
|
||||
new ColumnDfn(13,"OrganisationRoleCodes",0,12,false,256),
|
||||
new ColumnDfn(13,"OrganisationRoleCount",2,-6,false,3),
|
||||
new ColumnDfn(13,"AdminComment",0,-9,false,2000),
|
||||
new ColumnDfn(13,"Notes",0,-9,false,2000),
|
||||
new ColumnDfn(13,"Flags",3,5,false,5),
|
||||
new ColumnDfn(13,"Status",0,12,false,3),
|
||||
new ColumnDfn(13,"CreateOn",9,93,false,23),
|
||||
new ColumnDfn(13,"CreateBy",4,4,false,10),
|
||||
new ColumnDfn(13,"CreateHost",0,12,false,100),
|
||||
new ColumnDfn(13,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(13,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(13,"UpdateHost",0,12,false,100),
|
||||
new ColumnDfn(13,"OnlineAt",9,93,false,16),
|
||||
new ColumnDfn(14,"Id",5,-5,true,19),
|
||||
new ColumnDfn(14,"UserAccountId",4,4,false,10),
|
||||
new ColumnDfn(14,"UserRoleCode",0,12,false,16),
|
||||
new ColumnDfn(14,"OrganisationId",4,4,false,10),
|
||||
new ColumnDfn(14,"OrganisationRoleCodes",0,12,false,256),
|
||||
new ColumnDfn(14,"OrganisationRoleCount",2,-6,false,3),
|
||||
new ColumnDfn(14,"AdminComment",0,-9,false,2000),
|
||||
new ColumnDfn(14,"Notes",0,-9,false,2000),
|
||||
new ColumnDfn(14,"Flags",3,5,false,5),
|
||||
new ColumnDfn(14,"Status",0,12,false,3),
|
||||
@@ -812,42 +806,31 @@ namespace Saxonite.Base.App
|
||||
new ColumnDfn(14,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(14,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(14,"UpdateHost",0,12,false,100),
|
||||
new ColumnDfn(15,"Id",5,-5,true,19),
|
||||
new ColumnDfn(15,"UserAccountId",4,4,false,10),
|
||||
new ColumnDfn(15,"ActivityIndexIds",0,-9,false,0),
|
||||
new ColumnDfn(15,"UserSessionData",0,-9,false,0),
|
||||
new ColumnDfn(15,"UserRoleCode",0,12,false,16),
|
||||
new ColumnDfn(15,"Notes",0,-9,false,2000),
|
||||
new ColumnDfn(15,"Flags",3,5,false,5),
|
||||
new ColumnDfn(15,"Status",0,12,false,3),
|
||||
new ColumnDfn(15,"CreateOn",9,93,false,23),
|
||||
new ColumnDfn(15,"CreateBy",4,4,false,10),
|
||||
new ColumnDfn(15,"CreateHost",0,12,false,100),
|
||||
new ColumnDfn(15,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(16,"Id",5,-5,true,19),
|
||||
new ColumnDfn(15,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(15,"UpdateHost",0,12,false,100),
|
||||
new ColumnDfn(16,"UserAccountId",4,4,false,10),
|
||||
new ColumnDfn(16,"SportId",4,4,false,10),
|
||||
new ColumnDfn(16,"About",0,-9,false,2000),
|
||||
new ColumnDfn(16,"Participation",3,5,false,5),
|
||||
new ColumnDfn(16,"Officiating",3,5,false,5),
|
||||
new ColumnDfn(16,"UserSportData",0,-9,false,0),
|
||||
new ColumnDfn(16,"Notes",0,-9,false,2000),
|
||||
new ColumnDfn(16,"ActivityIndexIds",0,-9,false,0),
|
||||
new ColumnDfn(16,"UserSessionData",0,-9,false,0),
|
||||
new ColumnDfn(16,"Flags",3,5,false,5),
|
||||
new ColumnDfn(16,"Status",0,12,false,3),
|
||||
new ColumnDfn(16,"CreateOn",9,93,false,23),
|
||||
new ColumnDfn(16,"CreateBy",4,4,false,10),
|
||||
new ColumnDfn(16,"CreateHost",0,12,false,100),
|
||||
new ColumnDfn(16,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(16,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(16,"UpdateHost",0,12,false,100),
|
||||
new ColumnDfn(17,"Id",5,-5,true,19),
|
||||
new ColumnDfn(17,"UserSportId",5,-5,false,19),
|
||||
new ColumnDfn(17,"PeriodFrom",9,93,false,16),
|
||||
new ColumnDfn(17,"PeriodTo",9,93,false,16),
|
||||
new ColumnDfn(17,"OrganisationId",4,4,false,10),
|
||||
new ColumnDfn(17,"OrganisationName",0,-9,false,200),
|
||||
new ColumnDfn(17,"Summary",0,-9,false,2000),
|
||||
new ColumnDfn(17,"Team",0,-9,false,64),
|
||||
new ColumnDfn(17,"League",0,-9,false,64),
|
||||
new ColumnDfn(17,"Speciality",0,-9,false,64),
|
||||
new ColumnDfn(17,"SpecialitiesOther",0,-9,false,1000),
|
||||
new ColumnDfn(17,"RegionIdNation",4,4,false,10),
|
||||
new ColumnDfn(17,"RegionIdProvince",4,4,false,10),
|
||||
new ColumnDfn(17,"UserSportExperienceData",0,-9,false,0),
|
||||
new ColumnDfn(17,"UserAccountId",4,4,false,10),
|
||||
new ColumnDfn(17,"SportId",4,4,false,10),
|
||||
new ColumnDfn(17,"About",0,-9,false,2000),
|
||||
new ColumnDfn(17,"Participation",3,5,false,5),
|
||||
new ColumnDfn(17,"Officiating",3,5,false,5),
|
||||
new ColumnDfn(17,"UserSportData",0,-9,false,0),
|
||||
new ColumnDfn(17,"Notes",0,-9,false,2000),
|
||||
new ColumnDfn(17,"Flags",3,5,false,5),
|
||||
new ColumnDfn(17,"Status",0,12,false,3),
|
||||
@@ -857,6 +840,29 @@ namespace Saxonite.Base.App
|
||||
new ColumnDfn(17,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(17,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(17,"UpdateHost",0,12,false,100),
|
||||
new ColumnDfn(18,"Id",5,-5,true,19),
|
||||
new ColumnDfn(18,"UserSportId",5,-5,false,19),
|
||||
new ColumnDfn(18,"PeriodFrom",9,93,false,16),
|
||||
new ColumnDfn(18,"PeriodTo",9,93,false,16),
|
||||
new ColumnDfn(18,"OrganisationId",4,4,false,10),
|
||||
new ColumnDfn(18,"OrganisationName",0,-9,false,200),
|
||||
new ColumnDfn(18,"Summary",0,-9,false,2000),
|
||||
new ColumnDfn(18,"Team",0,-9,false,64),
|
||||
new ColumnDfn(18,"League",0,-9,false,64),
|
||||
new ColumnDfn(18,"Speciality",0,-9,false,64),
|
||||
new ColumnDfn(18,"SpecialitiesOther",0,-9,false,1000),
|
||||
new ColumnDfn(18,"RegionIdNation",4,4,false,10),
|
||||
new ColumnDfn(18,"RegionIdProvince",4,4,false,10),
|
||||
new ColumnDfn(18,"UserSportExperienceData",0,-9,false,0),
|
||||
new ColumnDfn(18,"Notes",0,-9,false,2000),
|
||||
new ColumnDfn(18,"Flags",3,5,false,5),
|
||||
new ColumnDfn(18,"Status",0,12,false,3),
|
||||
new ColumnDfn(18,"CreateOn",9,93,false,23),
|
||||
new ColumnDfn(18,"CreateBy",4,4,false,10),
|
||||
new ColumnDfn(18,"CreateHost",0,12,false,100),
|
||||
new ColumnDfn(18,"UpdateOn",9,93,false,23),
|
||||
new ColumnDfn(18,"UpdateBy",4,4,false,10),
|
||||
new ColumnDfn(18,"UpdateHost",0,12,false,100),
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public bool DebugMode { get; } = SacsSystem.DebugMode;
|
||||
public SaxSystem System { get; }
|
||||
public SaxSessionContext SessionContext { get; }
|
||||
public ISacsDatabase CoreDatabase { get { return SaxGlobals.App.GetCoreDatabase(SessionContext); } }
|
||||
@@ -113,6 +114,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
// Consoles.
|
||||
public SaxConsoleHelper ConsoleHelper { get { return SaxGlobals.App.ConsoleHelper; } }
|
||||
public SaxDataCacheConsole DataCacheConsole { get { return SaxGlobals.ConsoleHelper.GetDataCacheConsole(SessionContext); } }
|
||||
public SaxSessionDataConsole SessionDataConsole { get { return SaxGlobals.ConsoleHelper.GetSessionDataConsole(SessionContext); } }
|
||||
public SaxActivityConsole ActivityConsole { get { if (con.activityConsole == null) con.activityConsole = ConsoleHelper.CreateActivityConsole(SessionContext); return con.activityConsole; } }
|
||||
public SaxEmailConsole EmailConsole { get { if (con.emailConsole == null) con.emailConsole = ConsoleHelper.CreateEmailConsole(SessionContext); return con.emailConsole; } }
|
||||
|
||||
@@ -166,7 +168,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
foreach (SaxRegion.Data regionData in regions)
|
||||
regionCache[regionData.Id] = regionData.Clone();
|
||||
regionCacheFullyPopulated = true;
|
||||
SaLogger.Debug(GetType().Name + ".PopulateRegionCache(regions) Regions populated: " + regionCache.Count);
|
||||
//if (DebugMode) SaLogger.Debug(GetType().Name + ".PopulateRegionCache(regions) Regions populated: " + regionCache.Count);
|
||||
}
|
||||
public void RefreshRegionCache()
|
||||
{
|
||||
@@ -234,7 +236,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
foreach (SaxSport.Data sportData in sports)
|
||||
sportCache[sportData.Id] = sportData.Clone();
|
||||
sportCacheFullyPopulated = true;
|
||||
SaLogger.Debug(GetType().Name + ".PopulateSportCache(sports) Sports populated: " + sportCache.Count);
|
||||
//if (DebugMode) SaLogger.Debug(GetType().Name + ".PopulateSportCache(sports) Sports populated: " + sportCache.Count);
|
||||
}
|
||||
public void RefreshSportCache()
|
||||
{
|
||||
|
||||
@@ -137,6 +137,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
// Organisation categories.
|
||||
organisationCategoryCodes.Add(Sax.OrganisationCategory.Association, "ASC", "Association");
|
||||
organisationCategoryCodes.Add(Sax.OrganisationCategory.Club, "CLB", "Club");
|
||||
organisationCategoryCodes.Add(Sax.OrganisationCategory.Society, "SOC", "Society");
|
||||
organisationCategoryCodes.Add(Sax.OrganisationCategory.Education, "EDU", "Education");
|
||||
organisationCategoryCodes.Add(Sax.OrganisationCategory.Syndicate, "SYN", "Syndicate");
|
||||
organisationCategoryCodes.Add(Sax.OrganisationCategory.Partner, "PRT", "Partner");
|
||||
|
||||
@@ -267,6 +267,7 @@ namespace Saxonite.Net.Standard.Base.Bus
|
||||
public String NameFull { get; set; }
|
||||
public String NamePartial { get; set; }
|
||||
public Sax.OrganisationCategory OrganisationCategory { get; set; } = Sax.OrganisationCategory.Unknown;
|
||||
public List<Sax.OrganisationCategory> OrganisationCategoriesExcluded { get; } = new List<Sax.OrganisationCategory>();
|
||||
public Sax.OrganisationType OrganisationType { get; set; } = Sax.OrganisationType.Unknown;
|
||||
/// <summary>Partial match on a number of fields, including name, sport, address, etc.</summary>
|
||||
public String OrganisationFilter { get; set; }
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Saxonite.Net.Standard.Base.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
// UserRole.
|
||||
//=======================================================================
|
||||
public abstract class SaxUserOnline : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
UserAccountId,
|
||||
OnlineOn,
|
||||
OnlineAt,
|
||||
// User properties.
|
||||
EmailAddress,
|
||||
Title, FirstName, LastName,
|
||||
LastLoginAt,
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Properties other than common.</summary>
|
||||
public class DataProperties
|
||||
{
|
||||
public SysId UserAccountId { get; set; }
|
||||
public DateTime OnlineAt { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
// Data members.
|
||||
private readonly DataProperties data = new DataProperties();
|
||||
// Construction.
|
||||
public Data()
|
||||
{
|
||||
}
|
||||
// Properties.
|
||||
public SysId UserAccountId
|
||||
{
|
||||
get { return data.UserAccountId; }
|
||||
set { CheckChanged(data.UserAccountId, value); data.UserAccountId = value; }
|
||||
}
|
||||
public DateTime OnlineAt
|
||||
{
|
||||
get { return data.OnlineAt; }
|
||||
set { CheckChanged(data.OnlineAt, value); data.OnlineAt = value; }
|
||||
}
|
||||
// Population.
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
UserAccountId = data.UserAccountId;
|
||||
OnlineAt = data.OnlineAt;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Error field - identify properties with validation error.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
// Identifies the field that has invalid data.
|
||||
public ValidValue UserAccountId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue OnlineAt { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SaxUserOnline(SysId userAccountId) : base()
|
||||
{
|
||||
base.SetData(data);
|
||||
UserAccountId = userAccountId;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public Data GetData() { return data.Clone(); }
|
||||
public void SetData(Data data)
|
||||
{
|
||||
String fn = GetType().Name + ".SetData";
|
||||
// Properties that cannot be changed if previously specified.
|
||||
if (SysId.IsValid(UserAccountId) && SysId.ToInt(UserAccountId) != SysId.ToInt(data.UserAccountId))
|
||||
throw new NotSupportedException(fn + " User Account Id cannot be changed");
|
||||
this.data.PopulateFrom(data);
|
||||
}
|
||||
/// <summary>User Account Id. NB Can only be set where previously invalid.</summary>
|
||||
public SysId UserAccountId
|
||||
{
|
||||
get { return data.UserAccountId; }
|
||||
set
|
||||
{
|
||||
if (SysId.IsValid(UserAccountId) && SysId.ToInt(UserAccountId) != SysId.ToInt(data.UserAccountId))
|
||||
throw new NotSupportedException("UserRole.UserAccountId cannot be changed");
|
||||
data.UserAccountId = value;
|
||||
}
|
||||
}
|
||||
/// <summary>Online At - last time user was active Online.</summary>
|
||||
public DateTime OnlineAt
|
||||
{
|
||||
get { return data.OnlineAt; }
|
||||
set { data.OnlineAt = value; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Flags - positions 1-16 available.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// A s s o c i a t e d D a t a
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// P a r a m s
|
||||
//-------------------------------------------------------------------
|
||||
// List parameters.
|
||||
/// <summary>
|
||||
/// Item list parameters.
|
||||
/// </summary>
|
||||
public new class Params : SacsHierarchyItem.Params
|
||||
{
|
||||
// List filtering.
|
||||
public List<SysId> UserAccountIdsIncluded { get; } = new List<SysId>();
|
||||
public DateTime OnlineOnFrom { get; set; }
|
||||
public DateTime OnlineOnTo { get; set; }
|
||||
/// <summary>Exact match on various user account properties including name, email etc.</summary>
|
||||
public String UserFilter { get; set; }
|
||||
/// <summary>Partial match on various user account properties including name, email etc. Not to be used in Online application!</summary>
|
||||
public String UserFilterPartial { get; set; }
|
||||
// User Account filters.
|
||||
public List<SysId> SportIdsIncluded { get; } = new List<SysId>();
|
||||
public List<SysId> RegionIdsIncluded { get; } = new List<SysId>();
|
||||
// Table aliases - blank if not linked.
|
||||
public String Alias_UserAccount { get; set; }
|
||||
public String Alias_UserSport { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// Item list extension methods.
|
||||
public static class SaxUserOnlineList
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -18,6 +18,10 @@ namespace Saxonite.Net.Standard.Base.Consoles
|
||||
// Data cache console.
|
||||
public abstract SaxDataCacheConsole GetDataCacheConsole(SaxSessionContext sessionContext);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Session data console.
|
||||
public abstract SaxSessionDataConsole GetSessionDataConsole(SaxSessionContext sessionContext);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Activity console.
|
||||
public abstract SaxActivityConsole CreateActivityConsole(SaxSessionContext sessionContext);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Saxonite.Net.Standard.Base.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
// Some session data is stored to the database but, to avoid potential
|
||||
// performance issues in action execution, the data to store is cached and
|
||||
// periodically committed in batches.
|
||||
//=======================================================================
|
||||
public abstract class SaxSessionDataConsole : SaErrorStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SaxInternals internals = null;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SaxSessionDataConsole(SaxSessionContext sessionContext)
|
||||
{
|
||||
SessionContext = sessionContext;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (internals != null) internals.Dispose(); internals = null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected SaxSessionContext SessionContext { get; }
|
||||
protected SaxInternals Internals { get { if (internals == null) internals = new SaxInternals(SessionContext); return internals; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User activity.
|
||||
//-------------------------------------------------------------------
|
||||
// Record latest user active time.
|
||||
public abstract bool RecordUserActive(SysId userAccountId, DateTime activeAt);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data commit.
|
||||
//-------------------------------------------------------------------
|
||||
public abstract DateTime LastDataCommit();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Base.App;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Saxonite.Net.Standard.Base.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SaxAccountMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// Account Mgr - User Online
|
||||
//*******************************************************************
|
||||
// Utilities.
|
||||
public abstract bool CommitUsersOnline(IEnumerable <SaxUserOnline.DataProperties> usersOnline);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create item.
|
||||
public abstract SaxUserOnline CreateUserOnline(SysId userAccountId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item exists.
|
||||
public bool UserOnlineExistsByUserAccountId(SysId userAccountId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(userAccountId)) return false;
|
||||
SaxUserOnline.Params prmUserOnline = new SaxUserOnline.Params();
|
||||
prmUserOnline.UserAccountIdsIncluded.Add(userAccountId);
|
||||
return GetUserOnlineCount(prmUserOnline) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual items.
|
||||
public abstract SaxUserOnline GetUserOnline(SaxUserOnline.Params prmUserOnline);
|
||||
public SaxUserOnline GetUserOnlineByUserAccountId(SysId userAccountId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(userAccountId)) return null;
|
||||
SaxUserOnline.Params prmUserOnline = new SaxUserOnline.Params();
|
||||
prmUserOnline.UserAccountIdsIncluded.Add(userAccountId);
|
||||
return GetUserOnline(prmUserOnline);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate item data.
|
||||
public bool IsValidUserOnline(SaxUserOnline userRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (userRole == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidUserOnlineData(userRole.GetData(), new SaxUserOnline.ErrField());
|
||||
}
|
||||
public virtual bool IsValidUserOnlineData(SaxUserOnline.Data data, SaxUserOnline.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// User Account.
|
||||
if (errField.UserAccountId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.UserAccountId))
|
||||
{
|
||||
errField.UserAccountId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("User Account Id must be specified");
|
||||
}
|
||||
// Online at.
|
||||
if (errField.OnlineAt != SacsHierarchyItem.ValidValue.Ignore && !DateUtil.IsValid(data.OnlineAt))
|
||||
{
|
||||
errField.OnlineAt = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("last online time must be specified");
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item database interface.
|
||||
public abstract bool InsertUserOnline(SaxUserOnline userRole, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateUserOnline(SaxUserOnline userRole, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool UserOnlineCanBeDeleted(SaxUserOnline userRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteUserOnline(SaxUserOnline userRole, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item list.
|
||||
public abstract ColumnDfn GetUserOnlineColumnDfn(SaxUserOnline.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetUserOnlineQueryFilter(SaxUserOnline.Params prmUserOnline);
|
||||
public abstract long GetUserOnlineCount(SaxUserOnline.Params prmUserOnline);
|
||||
public abstract List<SaxUserOnline> GetUserOnlineList(SaxUserOnline.Params prmUserOnline);
|
||||
public abstract DbResultSet ExecuteUserOnlineQuery(List<ColumnDfn> columns, SaxUserOnline.Params prmUserOnline);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Extract and format result set data value where specific handling is required.
|
||||
/// <para>Where response is an invalid data value, format value using column.FormatValue(values).</para>
|
||||
/// </summary>
|
||||
public virtual DataValue GetUserOnlineDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SaxUserOnline.Column)column.Id)
|
||||
{
|
||||
//-----------------------------------------------------------
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Saxonite.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public class SaxUserOnline_Dbas : SaxUserOnline
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private ISacsDatabase database;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SaxUserOnline_Dbas (ISacsDatabase database, SysId userAccountId) :
|
||||
base(userAccountId)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Standard.Dbas.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
internal class UserOnline_Db : SaxDbDataItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Column definitions.
|
||||
public class ColumnsData
|
||||
{
|
||||
public ColumnDataInt32 _UserAccountId { get; } = new ColumnDataInt32("UserAccountId");
|
||||
public ColumnDataDateTime _OnlineAt { get; } = new ColumnDataDateTime("OnlineAt");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
protected static List<String> fields { get; } = new List<String>()
|
||||
{
|
||||
"UserAccountId",
|
||||
"OnlineAt",
|
||||
};
|
||||
protected static List<String> fieldsId { get; } = new List<String>()
|
||||
{
|
||||
};
|
||||
protected static List<String> fieldsPrimary { get; } = new List<String>()
|
||||
{
|
||||
"UserAccountId",
|
||||
};
|
||||
protected static List<String> fieldsIgnoreOnUpdate { get; } = new List<String>()
|
||||
{
|
||||
"CreateOn",
|
||||
"CreateBy",
|
||||
"CreateHost",
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
internal UserOnline_Db (IDatabaseInfo dbInfo) : base(dbInfo)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public override String SchemaName { get; } = "dbo";
|
||||
public override String TableName { get; } = "UserOnline";
|
||||
public String TableNameFmt { get { return (!String.IsNullOrEmpty(SchemaName) ? "[" + SchemaName + "]." : "") + "[" + TableName + "]"; } }
|
||||
public static List<String> Fields { get { return new List<String>(fields); } }
|
||||
public static List<String> FieldsId { get { return new List<String>(fieldsId); } }
|
||||
public static List<String> FieldsNonId { get { return fields.FindAll(item => !fieldsId.ContainsCI(item)); } }
|
||||
// Columns.
|
||||
public ColumnsData Cols { get; } = new ColumnsData();
|
||||
public Int32 _UserAccountId { get { return Cols._UserAccountId.Value; } set { Cols._UserAccountId.Value = value; } }
|
||||
public DateTime _OnlineAt { get { return Cols._OnlineAt.Value; } set { Cols._OnlineAt.Value = value; } }
|
||||
// Existing columns - confirmed on database if table exists.
|
||||
public List<String> ExistingColumnNames { get { return GetExistingColumnNames(Fields); } }
|
||||
public List<String> ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Population.
|
||||
public override void PopulateFrom (DbCommand dbCommand, String tableAlias, String filter)
|
||||
{
|
||||
dbCommand.CommandText =
|
||||
"SELECT " + ExistingColumnNames.Concat(", ", (!String.IsNullOrEmpty(tableAlias) ? tableAlias + "." : "") + "[", "]") + " " +
|
||||
"FROM " + TableNameFmt + (!String.IsNullOrEmpty(tableAlias) ? " " + tableAlias : "") + " " +
|
||||
(!String.IsNullOrEmpty(filter) ? "WHERE " + filter : "");
|
||||
Log(GetType().Name + ".PopulateFrom", dbCommand.CommandText);
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
dbDataReader.Read();
|
||||
PopulateFrom(dbDataReader);
|
||||
}
|
||||
}
|
||||
public override void PopulateFrom (DbDataReader dbDataReader)
|
||||
{
|
||||
_UserAccountId = GetFieldInt32(dbDataReader, "UserAccountId", _UserAccountId);
|
||||
_OnlineAt = GetFieldDateTime(dbDataReader, "OnlineAt", _OnlineAt);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert command.
|
||||
public override bool ExecuteInsertCommand (DbCommand dbCommand)
|
||||
{
|
||||
List<String> columnNames = ExistingColumnNamesNonId;
|
||||
// Construct query.
|
||||
String query =
|
||||
"INSERT INTO " + TableNameFmt + " " +
|
||||
"("+columnNames.Concat(",","[","]")+") ";
|
||||
if (dbCommand is SqlCommand)
|
||||
query += "VALUES (" + columnNames.Concat(",", "@", "") + ") ";
|
||||
else query += "VALUES (" + StringListUtil.CreateList("?", columnNames.Count).Concat(",") + ") ";
|
||||
dbCommand.CommandText = query;
|
||||
Log(GetType().Name + ".ExecuteInsertCommand", dbCommand.CommandText);
|
||||
// Populate parameters.
|
||||
dbCommand.Parameters.Clear();
|
||||
if (columnNames.ContainsCI("UserAccountId")) AddCommandParameter(dbCommand, "@UserAccountId", _UserAccountId);
|
||||
if (columnNames.ContainsCI("OnlineAt")) AddCommandParameter(dbCommand, "@OnlineAt", _OnlineAt);
|
||||
// Execute insert command.
|
||||
bool commandSuccess = false;
|
||||
int executeNonQuery = dbCommand.ExecuteNonQuery();
|
||||
if (executeNonQuery == 1)
|
||||
{
|
||||
commandSuccess = true;
|
||||
}
|
||||
return commandSuccess;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update command.
|
||||
public override bool ExecuteUpdateCommand (DbCommand dbCommand)
|
||||
{
|
||||
// Columns to update.
|
||||
List<String> columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList();
|
||||
// Construct query.
|
||||
String query = "UPDATE " + TableNameFmt + " SET ";
|
||||
if (dbCommand is SqlCommand)
|
||||
{
|
||||
query += StringPairList.CreateFrom(columnNames.Bracket("[","]"),columnNames).Concat("=@").Concat(", ") + " ";
|
||||
query += "WHERE UserAccountId=@UserAccountId;";
|
||||
}
|
||||
else
|
||||
{
|
||||
query += columnNames.Concat(", ", "", "=?") + " ";
|
||||
query += "WHERE UserAccountId=?;";
|
||||
}
|
||||
dbCommand.CommandText = query;
|
||||
Log(GetType().Name + ".ExecuteUpdateCommand", dbCommand.CommandText);
|
||||
// Populate parameters.
|
||||
dbCommand.Parameters.Clear();
|
||||
if (columnNames.ContainsCI("OnlineAt")) AddCommandParameter(dbCommand, "@OnlineAt", _OnlineAt);
|
||||
AddCommandParameter(dbCommand, "@UserAccountId", _UserAccountId);
|
||||
int executeNonQueryResult = dbCommand.ExecuteNonQuery();
|
||||
return (executeNonQueryResult == 1);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Code generated by Sarand Database Utilities Wed 8-Dec-2021 14:16:53
|
||||
// Code generated by Sarand Database Utilities Sat 15-Jan-2022 16:34:34
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Saxonite.Net.Standard.Dbas.Internal
|
||||
{
|
||||
|
||||
@@ -403,6 +403,8 @@ namespace Saxonite.Net.Standard.Dbas.Mgr
|
||||
// Organisation Category.
|
||||
if (prm.OrganisationCategory > 0)
|
||||
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Organisation_OrganisationCategory, aliasOrganisation) + "='" + OrganisationCategoryCodes.GetCodeForType(prm.OrganisationCategory) + "'");
|
||||
if (!prm.OrganisationCategoriesExcluded.IsEmpty())
|
||||
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Organisation_OrganisationCategory, aliasOrganisation) + " Not In (" + prm.OrganisationCategoriesExcluded.Select(cat => "'" + OrganisationCategoryCodes.GetCodeForType(cat) + "'").Concat(",") + ")");
|
||||
|
||||
// Organisation filter.
|
||||
if (!StringUtil.IsEmpty(prm.OrganisationFilter))
|
||||
|
||||
@@ -0,0 +1,552 @@
|
||||
using Sarand.Net.Standard.Dbas.Data;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Saxonite.Base.App;
|
||||
using Saxonite.Net.Standard.Dbas.Bus;
|
||||
using Saxonite.Net.Standard.Dbas.Internal;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using System.Linq;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
namespace Saxonite.Net.Standard.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SaxAccountMgr_Dbas
|
||||
{
|
||||
//*******************************************************************
|
||||
// Account Mgr - User Role
|
||||
//*******************************************************************
|
||||
// Utilities.
|
||||
private List<StringPair> GetLogProperties(SaxUserOnline userOnline)
|
||||
{
|
||||
return new List<StringPair>()
|
||||
{
|
||||
new StringPair("UserAccountId",SysId.ToString(userOnline.UserAccountId)),
|
||||
new StringPair("OnlineAt",DateUtil.Format(userOnline.OnlineAt, "d-MMM-yyyy HH:mm:ss")),
|
||||
};
|
||||
}
|
||||
|
||||
public override bool CommitUsersOnline(IEnumerable<SaxUserOnline.DataProperties> usersOnline)
|
||||
{
|
||||
String fn = GetType().Name + ".CommitUsersOnline";
|
||||
try
|
||||
{
|
||||
// Merge query - insert missing user activities and update existing.
|
||||
List<String> query = new List<String>()
|
||||
{
|
||||
"Merge",
|
||||
" Into " + SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOnline) + " As UsrOnl",
|
||||
// Virtual table defining Activity Item Ids currently listed.
|
||||
" Using",
|
||||
" (",
|
||||
" Select UserAccountId, OnlineAt From (Select 0 UserAccountId, null OnlineAt" + usersOnline.Select(item => " Union Select " + item.UserAccountId.ToString() + ", " + DbQuery.FormatDateTimeForCondition(item.OnlineAt)).ToList().Concat("", " ") + ") Dat Where Dat.UserAccountId>0 And Dat.OnlineAt Is Not Null",
|
||||
" ) As DatOnl",
|
||||
" On UsrOnl.UserAccountId=DatOnl.UserAccountId",
|
||||
// Matched - Update the User Online to store latest Online data.
|
||||
" When Matched Then",
|
||||
" Update Set OnlineAt=DatOnl.OnlineAt",
|
||||
// Not Matched By Target - Insert the User Online with latest data.
|
||||
" When Not Matched Then",
|
||||
" Insert",
|
||||
" (UserAccountId, OnlineAt)",
|
||||
" Values (DatOnl.UserAccountId, DatOnl.OnlineAt)",
|
||||
";"
|
||||
};
|
||||
String sql = query.Concat("\n");
|
||||
//SaLogger.Debug(fn + " Query:\n" + sql);
|
||||
ISacsDatabase db = SaxGlobals.App.GetCoreDatabase(SessionContext);
|
||||
int rows = db.ExecuteNonQuery(sql);
|
||||
if (db.HasErrorState())
|
||||
SaLogger.Error(fn + " Database error: " + db.ErrorStateMessage);
|
||||
SaLogger.Debug(fn + " UserOnline rows modified: " + rows);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn(fn + " ");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create item.
|
||||
public override SaxUserOnline CreateUserOnline(SysId userAccountId)
|
||||
{
|
||||
ClearErrorState();
|
||||
return new SaxUserOnline_Dbas(CoreDatabase, userAccountId);
|
||||
}
|
||||
private SaxUserOnline_Dbas CreateUserOnline(UserOnline_Db dbUserOnline)
|
||||
{
|
||||
ClearErrorState();
|
||||
SaxUserOnline_Dbas userOnline = new SaxUserOnline_Dbas(CoreDatabase, new SysId(dbUserOnline._UserAccountId));
|
||||
PopulateFrom(dbUserOnline, userOnline);
|
||||
return userOnline;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get item.
|
||||
public override SaxUserOnline GetUserOnline(SaxUserOnline.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetUserOnline(GetUserOnlineQueryFilter(prm).Concat(" And ", "(", ")"));
|
||||
}
|
||||
private SaxUserOnline GetUserOnline(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetUserOnlineCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple items found");
|
||||
return null;
|
||||
}
|
||||
SaxUserOnline userOnline = null;
|
||||
// Query data.
|
||||
using (var dbConnection = CoreDatabase.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
UserOnline_Db dbUserOnline = new UserOnline_Db(CoreDbInfo);
|
||||
dbUserOnline.PopulateFrom(dbCommand, aliasUserOnline, filter);
|
||||
userOnline = CreateUserOnline(dbUserOnline);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
SaLogger.Warn(GetType().Name + ".GetUserOnline\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
|
||||
}
|
||||
}
|
||||
return userOnline;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate item.
|
||||
public override bool IsValidUserOnlineData(SaxUserOnline.Data data, SaxUserOnline.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidUserOnlineData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert item.
|
||||
public override bool InsertUserOnline(SaxUserOnline userOnline, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
String fn = GetType().Name + ".InsertUserOnline";
|
||||
ClearErrorState();
|
||||
if (!IsValidUserOnline(userOnline)) return false;
|
||||
if (SysId.IsValid(userOnline.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = CoreDatabase.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
UserOnline_Db dbUserOnline = new UserOnline_Db(CoreDbInfo);
|
||||
PopulateTo(dbUserOnline, userOnline, dbUpdateInfo);
|
||||
if (UserOnline_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// User Online has no Id.
|
||||
}
|
||||
dbUserOnline.ExecuteInsertCommand(dbCommand);
|
||||
userOnline.Changed = false;
|
||||
if (DebugMode) SaLogger.Debug(fn + " Inserted. " + GetLogProperties(userOnline).Concat(": ").Concat("", "\n\t"));
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update item.
|
||||
public override bool UpdateUserOnline(SaxUserOnline userOnline, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
String fn = GetType().Name + ".UpdateUserOnline";
|
||||
ClearErrorState();
|
||||
if (!IsValidUserOnline(userOnline)) return false;
|
||||
if (!SysId.IsValid(userOnline.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
if (!userOnline.Changed)
|
||||
{
|
||||
if (DebugMode) SaLogger.Debug(fn + " Data not changed. " + GetLogProperties(userOnline).Concat(": ").Concat("", "\n\t"));
|
||||
return true;
|
||||
}
|
||||
using (var dbConnection = CoreDatabase.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve item.
|
||||
dbConnection.Open();
|
||||
UserOnline_Db dbUserOnline = new UserOnline_Db(CoreDbInfo);
|
||||
dbUserOnline.PopulateFrom(dbCommand, aliasUserOnline, "UserAccountId=" + SysId.ToString(userOnline.UserAccountId));
|
||||
// ToDo SaxUpdateLogItemMonitor_UserOnline updateLogMonitor = new SaxUpdateLogItemMonitor_UserOnline(SessionContext, CreateUserOnline(dbUserOnline), dbUpdateInfo);
|
||||
// Update item.
|
||||
PopulateTo(dbUserOnline, userOnline, dbUpdateInfo);
|
||||
dbUserOnline.ExecuteUpdateCommand(dbCommand);
|
||||
userOnline.Changed = false;
|
||||
if (DebugMode) SaLogger.Debug(fn + " Updated. " + GetLogProperties(userOnline).Concat(": ").Concat("", "\n\t"));
|
||||
// Record updates.
|
||||
// ToDo updateLogMonitor.RecordUpdatedValues(userOnline);
|
||||
// ToDo updateLogMonitor.LogUpdates();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete item.
|
||||
public override bool UserOnlineCanBeDeleted(SaxUserOnline userOnline)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.UserOnlineCanBeDeleted(userOnline)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteUserOnline(SaxUserOnline userOnline, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
String fn = GetType().Name + ".DeleteUserOnline";
|
||||
ClearErrorState();
|
||||
if (!UserOnlineCanBeDeleted(userOnline)) return false;
|
||||
using (var dbConnection = CoreDatabase.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve item.
|
||||
dbConnection.Open();
|
||||
UserOnline_Db dbUserOnline = new UserOnline_Db(CoreDbInfo);
|
||||
dbUserOnline.PopulateFrom(dbCommand, aliasUserOnline, "Id=" + userOnline.Id.ToString());
|
||||
// Delete item.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOnline) + " WHERE UserAccountId=" + SysId.ToString(userOnline.UserAccountId) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
userOnline.Changed = false;
|
||||
if (DebugMode) SaLogger.Debug(fn + " Deleted. " + GetLogProperties(userOnline).Concat(": ").Concat("", "\n\t"));
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(UserOnline_Db dbUserOnline, SaxUserOnline userOnline, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbUserOnline._UserAccountId = SysId.ToInt(userOnline.UserAccountId);
|
||||
dbUserOnline._OnlineAt = userOnline.OnlineAt;
|
||||
}
|
||||
private void PopulateFrom(UserOnline_Db dbUserOnline, SaxUserOnline userOnline)
|
||||
{
|
||||
//userOnline.UserAccountId = new SysId(dbUserOnline._UserAccountId);
|
||||
userOnline.OnlineAt = dbUserOnline._OnlineAt;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item column definitions.
|
||||
private static readonly String aliasUserOnline = "UsrRol";
|
||||
private static readonly String aliasUserOnline_UserAccount = "UsrRol_Usr";
|
||||
private static readonly String prefixUserOnline_UserAccount = "UsrRol_Usr_";
|
||||
private static readonly String aliasUserOnline_UserSport = "UsrOnl_UsrSpt";
|
||||
private void SetUserOnlineColDfn
|
||||
(ColumnDfn col, String caption, int width, SaxDbDfn_Core.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SaxDbDfn_Core.GetTableForColumn(dbCol) == SaxDbDfn_Core.TableIdx.UserOnline)
|
||||
alias = aliasUserOnline;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SaxDbDfn_Core.GetColumnName(dbCol, false), SaxDbDfn_Core.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SaxDbDfn_Core.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SaxDbDfn_Core.GetColTextLen(dbCol);
|
||||
}
|
||||
public override ColumnDfn GetUserOnlineColumnDfn(SaxUserOnline.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
//-----------------------------------------------------------
|
||||
case SaxUserOnline.Column.Pos:
|
||||
SetUserOnlineColDfn(columnDfn, "Pos", 60, SaxDbDfn_Core.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SaxUserOnline.Column.UserAccountId:
|
||||
SetUserOnlineColDfn(columnDfn, "User Id", 80, SaxDbDfn_Core.ColumnIdx.UserOnline_UserAccountId, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SaxUserOnline.Column.OnlineOn:
|
||||
SetUserOnlineColDfn(columnDfn, "Online", 80, SaxDbDfn_Core.ColumnIdx.UserOnline_OnlineAt, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SaxUserOnline.Column.OnlineAt:
|
||||
SetUserOnlineColDfn(columnDfn, "Online", 100, SaxDbDfn_Core.ColumnIdx.UserOnline_OnlineAt, ColumnAlignment.Center, DataValue.DataType.DateTime);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
//-------------------------------------------------------
|
||||
// User properties.
|
||||
case SaxUserOnline.Column.EmailAddress:
|
||||
SetUserOnlineColDfn(columnDfn, "Email", 160, SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress, ColumnAlignment.Left, DataValue.DataType.String, aliasUserOnline_UserAccount, prefixUserOnline_UserAccount);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SaxUserOnline.Column.Title:
|
||||
SetUserOnlineColDfn(columnDfn, "Title", 70, SaxDbDfn_Core.ColumnIdx.UserAccount_Title, ColumnAlignment.Left, DataValue.DataType.String, aliasUserOnline_UserAccount, prefixUserOnline_UserAccount);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SaxUserOnline.Column.FirstName:
|
||||
SetUserOnlineColDfn(columnDfn, "First name", 120, SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName, ColumnAlignment.Left, DataValue.DataType.String, aliasUserOnline_UserAccount, prefixUserOnline_UserAccount);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SaxUserOnline.Column.LastName:
|
||||
SetUserOnlineColDfn(columnDfn, "Last name", 120, SaxDbDfn_Core.ColumnIdx.UserAccount_LastName, ColumnAlignment.Left, DataValue.DataType.String, aliasUserOnline_UserAccount, prefixUserOnline_UserAccount);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SaxUserOnline.Column.LastLoginAt:
|
||||
SetUserOnlineColDfn(columnDfn, "Last login", 100, SaxDbDfn_Core.ColumnIdx.UserAccount_LastLoginAt, ColumnAlignment.Center, DataValue.DataType.DateTime, aliasUserOnline_UserAccount, prefixUserOnline_UserAccount);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
//-------------------------------------------------------
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item query filter.
|
||||
public override List<string> GetUserOnlineQueryFilter(SaxUserOnline.Params prm)
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
|
||||
// User accounts.
|
||||
String userAccountIdsIncluded = prm.UserAccountIdsIncluded.Concat(",");
|
||||
if (!userAccountIdsIncluded.IsEmpty())
|
||||
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_UserAccountId, aliasUserOnline) + " IN (" + userAccountIdsIncluded + ")");
|
||||
|
||||
// Online On.
|
||||
if (DateUtil.IsValid(prm.OnlineOnFrom))
|
||||
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_OnlineAt, aliasUserOnline) + ">=" + DbQuery.FormatDateForCondition(prm.OnlineOnFrom));
|
||||
if (DateUtil.IsValid(prm.OnlineOnTo))
|
||||
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_OnlineAt, aliasUserOnline) + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.OnlineOnTo, 1)));
|
||||
|
||||
// User Account filters.
|
||||
String aliasUserOnline_UserAccount = StringUtil.OnEmpty(prm.Alias_UserAccount, SaxAccountMgr_Dbas.aliasUserOnline_UserAccount);
|
||||
List<String> userAccountFilters = new List<string>();
|
||||
// User filter - partial.
|
||||
userAccountFilters.AddRange(GetUserAccountFilters(prm.UserFilter, aliasUserOnline_UserAccount));
|
||||
userAccountFilters.AddRange(GetPartialUserAccountFilters(prm.UserFilterPartial, aliasUserOnline_UserAccount));
|
||||
// Sport Ids.
|
||||
String aliasUserOnline_UserSport = StringUtil.OnEmpty(prm.Alias_UserSport, SaxAccountMgr_Dbas.aliasUserOnline_UserSport);
|
||||
String sportIdsIncluded = prm.SportIdsIncluded.Concat(",");
|
||||
if (!sportIdsIncluded.IsEmpty())
|
||||
{
|
||||
List<String> userSportFilters = new List<string>();
|
||||
userSportFilters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserSport_SportId, aliasUserOnline_UserSport) + " IN (" + sportIdsIncluded + ")");
|
||||
if (!userSportFilters.IsEmpty())
|
||||
{
|
||||
if (prm.Alias_UserSport.IsEmpty())
|
||||
{
|
||||
// User Sport table is not linked in query.
|
||||
DbQuery userSportQuery = new DbQuery(CoreDatabase.DbmsType);
|
||||
userSportQuery.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserSport), aliasUserOnline_UserSport);
|
||||
userSportQuery.Columns.Add("1");
|
||||
userSportQuery.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserSport_UserAccountId, aliasUserOnline_UserSport) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserAccount_Id, aliasUserOnline_UserAccount));
|
||||
userSportQuery.Filters.AddRange(userSportFilters);
|
||||
filter.Add("Exists(" + userSportQuery.BuildQuery() + ")");
|
||||
}
|
||||
else
|
||||
// User Sport table is already linked in the query.
|
||||
filter.AddRange(userSportFilters);
|
||||
}
|
||||
}
|
||||
// Region Ids.
|
||||
String regionIdsIncluded = prm.RegionIdsIncluded.Concat(",");
|
||||
if (!regionIdsIncluded.IsEmpty())
|
||||
{
|
||||
List<String> userRegionFilters = new List<string>();
|
||||
userRegionFilters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserAccount_RegionIdCountry, aliasUserOnline_UserAccount) + " IN (" + regionIdsIncluded + ")");
|
||||
userRegionFilters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserAccount_RegionIdProvince, aliasUserOnline_UserAccount) + " IN (" + regionIdsIncluded + ")");
|
||||
userAccountFilters.Add(userRegionFilters.Concat(" OR ", "", ""));
|
||||
}
|
||||
// User Account filter.
|
||||
if (!userAccountFilters.IsEmpty())
|
||||
{
|
||||
if (prm.Alias_UserAccount.IsEmpty())
|
||||
{
|
||||
// User Account table is not linked in query.
|
||||
DbQuery userAccountQuery = new DbQuery(CoreDatabase.DbmsType);
|
||||
userAccountQuery.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserAccount), aliasUserOnline_UserAccount);
|
||||
userAccountQuery.Columns.Add("1");
|
||||
userAccountQuery.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserAccount_Id, aliasUserOnline_UserAccount) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_UserAccountId, aliasUserOnline));
|
||||
userAccountQuery.Filters.AddRange(userAccountFilters);
|
||||
filter.Add("Exists(" + userAccountQuery.BuildQuery() + ")");
|
||||
}
|
||||
else
|
||||
// User Account table is already linked in the query.
|
||||
filter.AddRange(userAccountFilters);
|
||||
}
|
||||
|
||||
if (filter.Count < 1) filter.Add("1=1");
|
||||
return filter;
|
||||
}
|
||||
// Item sort columns.
|
||||
public List<String> GetUserOnlineSortColumns(SaxUserOnline.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for UserOnline columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SaxDbDfn_Core.GetTableForColumn((SaxDbDfn_Core.ColumnIdx)columnDfn.DbColumn) == SaxDbDfn_Core.TableIdx.UserOnline)
|
||||
{
|
||||
sortCol = SaxDbDfn_Core.GetColumnNameQual((SaxDbDfn_Core.ColumnIdx)columnDfn.DbColumn, aliasUserOnline);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns.
|
||||
sortColumnNames.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_OnlineAt, aliasUserOnline) + " DESC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item count.
|
||||
private long GetUserOnlineCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return CoreDatabase.GetRowCount(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOnline) + " As " + aliasUserOnline, filter);
|
||||
}
|
||||
public override long GetUserOnlineCount(SaxUserOnline.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetUserOnlineCount(GetUserOnlineQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item list.
|
||||
public override List<SaxUserOnline> GetUserOnlineList(SaxUserOnline.Params prm)
|
||||
{
|
||||
List<SaxUserOnline> userOnlines = new List<SaxUserOnline>();
|
||||
DbQuery qry = new DbQuery(CoreDatabase.DbmsType);
|
||||
qry.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOnline), aliasUserOnline);
|
||||
UserOnline_Db dbUserOnline = new UserOnline_Db(CoreDbInfo);
|
||||
qry.Columns.AddRange(dbUserOnline.ExistingColumnNames);
|
||||
qry.Filters.AddRange(GetUserOnlineQueryFilter(prm));
|
||||
qry.OrderBy.AddRange(GetUserOnlineSortColumns(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = CoreDatabase.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery(prm.ResultsPaging);
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
dbUserOnline = new UserOnline_Db(CoreDbInfo);
|
||||
dbUserOnline.PopulateFrom(dbDataReader);
|
||||
userOnlines.Add(CreateUserOnline(dbUserOnline));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn(GetType().Name + ".GetUserOnlineList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
|
||||
}
|
||||
}
|
||||
return userOnlines;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Item query execution.
|
||||
public override DbResultSet ExecuteUserOnlineQuery(List<ColumnDfn> columns, SaxUserOnline.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(CoreDatabase.DbmsType);
|
||||
query.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOnline), aliasUserOnline);
|
||||
|
||||
// Add columns as defined in query list.
|
||||
if (columns.HasId(SaxUserOnline.Column.UserAccountId))
|
||||
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_UserAccountId, aliasUserOnline));
|
||||
if (columns.HasId(SaxUserOnline.Column.OnlineOn) || columns.HasId(SaxUserOnline.Column.OnlineAt))
|
||||
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_OnlineAt, aliasUserOnline));
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// User Account.
|
||||
bool hasUserAccountCols = columns.HasId(SaxUserOnline.Column.EmailAddress) || columns.HasId(SaxUserOnline.Column.Title) || columns.HasId(SaxUserOnline.Column.FirstName) || columns.HasId(SaxUserOnline.Column.LastName) || columns.HasId(SaxUserOnline.Column.LastLoginAt);
|
||||
if (hasUserAccountCols)
|
||||
{
|
||||
prm.Alias_UserAccount = aliasUserOnline_UserAccount;
|
||||
DbQueryJoin joinUserAccount = new DbQueryJoin(DbJoinType.LeftOuter);
|
||||
joinUserAccount.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserAccount), aliasUserOnline_UserAccount);
|
||||
joinUserAccount.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserAccount_Id, aliasUserOnline_UserAccount) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOnline_UserAccountId, aliasUserOnline));
|
||||
List<SaxDbDfn_Core.ColumnIdx> cols = new List<SaxDbDfn_Core.ColumnIdx>();
|
||||
if (columns.HasId(SaxUserOnline.Column.EmailAddress))
|
||||
cols.Add(SaxDbDfn_Core.ColumnIdx.UserAccount_EmailAddress);
|
||||
if (columns.HasId(SaxUserOnline.Column.Title))
|
||||
cols.Add(SaxDbDfn_Core.ColumnIdx.UserAccount_Title);
|
||||
if (columns.HasId(SaxUserOnline.Column.FirstName))
|
||||
cols.Add(SaxDbDfn_Core.ColumnIdx.UserAccount_FirstName);
|
||||
if (columns.HasId(SaxUserOnline.Column.LastName))
|
||||
cols.Add(SaxDbDfn_Core.ColumnIdx.UserAccount_LastName);
|
||||
if (columns.HasId(SaxUserOnline.Column.LastLoginAt))
|
||||
cols.Add(SaxDbDfn_Core.ColumnIdx.UserAccount_LastLoginAt);
|
||||
if (cols.Count > 0)
|
||||
{
|
||||
foreach (var col in cols)
|
||||
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasUserOnline_UserAccount), prefixUserOnline_UserAccount + SaxDbDfn_Core.GetColumnName(col, false));
|
||||
query.Joins.Add(joinUserAccount);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetUserOnlineQueryFilter(prm));
|
||||
|
||||
if (prm.UserAccountIdsIncluded.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetUserOnlineSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery(prm.ResultsPaging));
|
||||
return DbResultSet_DataReader.ExecuteQuery(CoreDatabase, query.BuildQuery(prm.ResultsPaging));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -256,7 +256,7 @@
|
||||
<Clustered>false</Clustered>
|
||||
<Nullable>false</Nullable>
|
||||
<Pages>1</Pages>
|
||||
<UniqueValues>12</UniqueValues>
|
||||
<UniqueValues>14</UniqueValues>
|
||||
<HasColumns>false</HasColumns>
|
||||
<Columns>
|
||||
<DbDfnIndexColumn>
|
||||
@@ -2883,7 +2883,7 @@
|
||||
<Clustered>false</Clustered>
|
||||
<Nullable>false</Nullable>
|
||||
<Pages>1</Pages>
|
||||
<UniqueValues>1</UniqueValues>
|
||||
<UniqueValues>2</UniqueValues>
|
||||
<HasColumns>false</HasColumns>
|
||||
<Columns>
|
||||
<DbDfnIndexColumn>
|
||||
@@ -5005,7 +5005,7 @@
|
||||
<Clustered>false</Clustered>
|
||||
<Nullable>false</Nullable>
|
||||
<Pages>1</Pages>
|
||||
<UniqueValues>19</UniqueValues>
|
||||
<UniqueValues>21</UniqueValues>
|
||||
<HasColumns>false</HasColumns>
|
||||
<Columns>
|
||||
<DbDfnIndexColumn>
|
||||
@@ -5117,6 +5117,69 @@
|
||||
</DbDfnIndex>
|
||||
</Indices>
|
||||
</DbDfnTable>
|
||||
<DbDfnTable>
|
||||
<Schema>dbo</Schema>
|
||||
<Name>UserOnline</Name>
|
||||
<Remarks />
|
||||
<Columns>
|
||||
<DbDfnColumn>
|
||||
<Schema>dbo</Schema>
|
||||
<Table>UserOnline</Table>
|
||||
<Pos>1</Pos>
|
||||
<Name>UserAccountId</Name>
|
||||
<DataType>Int</DataType>
|
||||
<DataTypeName />
|
||||
<DataTypeNative>4</DataTypeNative>
|
||||
<DataTypeNameNative>int</DataTypeNameNative>
|
||||
<IsIdentity>false</IsIdentity>
|
||||
<Size>10</Size>
|
||||
<BufferLen>4</BufferLen>
|
||||
<DecimalDigits>0</DecimalDigits>
|
||||
<Nullable>NoNulls</Nullable>
|
||||
<IsNullable>false</IsNullable>
|
||||
<Remarks />
|
||||
</DbDfnColumn>
|
||||
<DbDfnColumn>
|
||||
<Schema>dbo</Schema>
|
||||
<Table>UserOnline</Table>
|
||||
<Pos>2</Pos>
|
||||
<Name>OnlineAt</Name>
|
||||
<DataType>DateTime</DataType>
|
||||
<DataTypeName />
|
||||
<DataTypeNative>93</DataTypeNative>
|
||||
<DataTypeNameNative>smalldatetime</DataTypeNameNative>
|
||||
<IsIdentity>false</IsIdentity>
|
||||
<Size>16</Size>
|
||||
<BufferLen>16</BufferLen>
|
||||
<DecimalDigits>0</DecimalDigits>
|
||||
<Nullable>NoNulls</Nullable>
|
||||
<IsNullable>false</IsNullable>
|
||||
<Remarks />
|
||||
</DbDfnColumn>
|
||||
</Columns>
|
||||
<Indices>
|
||||
<DbDfnIndex>
|
||||
<Schema>dbo</Schema>
|
||||
<Table>UserOnline</Table>
|
||||
<Name>PK_UserOnline</Name>
|
||||
<IndexType>1</IndexType>
|
||||
<Unique>true</Unique>
|
||||
<Primary>false</Primary>
|
||||
<Clustered>false</Clustered>
|
||||
<Nullable>false</Nullable>
|
||||
<Pages>0</Pages>
|
||||
<UniqueValues>0</UniqueValues>
|
||||
<HasColumns>false</HasColumns>
|
||||
<Columns>
|
||||
<DbDfnIndexColumn>
|
||||
<Seq>1</Seq>
|
||||
<Name>UserAccountId</Name>
|
||||
<Ascend>true</Ascend>
|
||||
</DbDfnIndexColumn>
|
||||
</Columns>
|
||||
</DbDfnIndex>
|
||||
</Indices>
|
||||
</DbDfnTable>
|
||||
<DbDfnTable>
|
||||
<Schema>dbo</Schema>
|
||||
<Name>UserOrganisation</Name>
|
||||
|
||||
Reference in New Issue
Block a user