Move Saxonite’s projects into a dedicated `Workspace` folder and align the solution with .NET 10 and the current Common workspace. Update encryption integration, test project structure and coverage, and repository guidance and upgrade notes. - Relocate application and library projects while retaining Git rename history. - Split tests into Admin, Online, and Shared projects; add representative behavioral and serialization tests. - Update Common integration, application version, and repository documentation. Application version: 1.3.0 Reviewed-on: #1 Co-authored-by: andy <andy@sarand.com>
136 lines
4.8 KiB
C#
136 lines
4.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Saxonite.Net.Core.Web.Online.Models;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using MailKit;
|
|
using Org.BouncyCastle.Asn1.Mozilla;
|
|
using Microsoft.Extensions.Primitives;
|
|
using Saxonite.Net.Standard.Base.Data;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Controllers
|
|
{
|
|
//=======================================================================
|
|
// Online Ajax Controller - User Config.
|
|
//=======================================================================
|
|
partial class AccountController
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Update User Config.
|
|
//-------------------------------------------------------------------
|
|
private class AjaxResponse_UserConfigData : AjaxResponse_Data
|
|
{
|
|
// Construction.
|
|
public AjaxResponse_UserConfigData(SaxModel_Online model) : base(model) { }
|
|
}
|
|
// Ajax request.
|
|
[HttpPost]
|
|
[Route("UserConfig/Ajax/Update")]
|
|
public IActionResult UpdateUserConfig(SaxModel_Online model)
|
|
{
|
|
String fn = GetType().Name + ".UpdateUserConfig";
|
|
AjaxResponse_UserConfigData responseData = new AjaxResponse_UserConfigData(model);
|
|
String messageTitle = Localiser["caption.user.config"];
|
|
|
|
// 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<IDisposable> disposableItems = new DisposableCollection<IDisposable>())
|
|
{
|
|
// Retrieve User Config.
|
|
Dictionary<Sax.UserConfigType, SaxUserConfig> userConfigs = new Dictionary<Sax.UserConfigType, SaxUserConfig>();
|
|
|
|
// Update user's configuration.
|
|
foreach (String key in Request.Form.Keys)
|
|
{
|
|
StringValues formValue = "";
|
|
Request.Form.TryGetValue(key, out formValue);
|
|
SaLogger.Debug(fn + " Form data. Key: " + key + ". Value: " + formValue);
|
|
if (key.EqualsCI("HideProfileEligibilityInfo"))
|
|
{
|
|
SaxUserConfig userConfig = RefreshUserConfig(Sax.UserConfigType.Online_Profile, userConfigs);
|
|
if (userConfig != null)
|
|
{
|
|
disposableItems.Add(userConfig);
|
|
SessionData_Online.UserConfig.Profile.Eligibility.HideInfo = StringUtil.ToBool(formValue);
|
|
userConfig.ConfigData = SaxConfigData.ProfileData.ToXml(SessionData_Online.UserConfig.Profile);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Store configuration.
|
|
foreach (SaxUserConfig userConfig in userConfigs.Values)
|
|
{
|
|
if (!SysId.IsValid(userConfig.Id))
|
|
{
|
|
// Add new configuration.
|
|
if (!AccountMgr.InsertUserConfig(userConfig, DbUpdateInfo))
|
|
SaLogger.Warn(fn + " Failed to insert User Config: " + AccountMgr.ErrorStateMessage);
|
|
}
|
|
else
|
|
{
|
|
// Update existing configuration.
|
|
if (!AccountMgr.UpdateUserConfig(userConfig, DbUpdateInfo))
|
|
SaLogger.Warn(fn + " Failed to update User Config: " + AccountMgr.ErrorStateMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Complete response.
|
|
responseData.Success = true;
|
|
return Json(responseData);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Retrieve the corresponding User Config if previously stored, otherwise create.
|
|
/// </summary>
|
|
private SaxUserConfig RefreshUserConfig(Sax.UserConfigType configType, Dictionary<Sax.UserConfigType, SaxUserConfig> userConfigs)
|
|
{
|
|
// Check if Config is already in cache.
|
|
if (userConfigs.ContainsKey(configType)) return userConfigs.GetValueOrDefault(configType, null);
|
|
// Retrieve user config.
|
|
SaxUserConfig userConfig = AccountMgr.GetUserConfig(SessionUserAccountId, configType);
|
|
if (userConfig == null)
|
|
{
|
|
// Configuration doesn't currently exist.
|
|
userConfig = AccountMgr.CreateUserConfig(SessionUserAccountId, configType);
|
|
}
|
|
else
|
|
{
|
|
// User Configuration already exists.
|
|
// Refresh configuration in case updated elsewhere.
|
|
switch (configType)
|
|
{
|
|
case Sax.UserConfigType.Online_Profile:
|
|
SessionData_Online.UserConfig.Profile = SaxConfigData.ProfileData.FromXml(userConfig.ConfigData);
|
|
break;
|
|
}
|
|
}
|
|
userConfigs.Add(userConfig.ConfigType, userConfig);
|
|
return userConfig;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|