Files
raven/server/AyaNova/util/ServerGlobalBizSettings.cs
2021-05-15 16:05:46 +00:00

55 lines
1.9 KiB
C#

using System;
using System.Linq;
using AyaNova.Models;
namespace AyaNova.Util
{
/// <summary>
/// Contains static mirror copy in memory of global settings values that are set from DB during boot
/// and accessible to Biz admin user (equivalent of v7's global object)
/// used by many areas of the biz logic and processing too often to fetch on every request
/// set at boot and on any update to the db global biz settings record
/// </summary>
internal static class ServerGlobalBizSettings
{
internal static bool SearchCaseSensitiveOnly { get; set; }
internal static bool UseInventory { get; set; }
internal static long? TaxPartPurchaseId { get; set; }
internal static long? TaxPartSaleId { get; set; }
internal static long? TaxRateSaleId { get; set; }
internal static TimeSpan WorkOrderCompleteByAge { get; set; }
/// <summary>
/// Populate and / or create the settings
/// </summary>
internal static void Initialize(GlobalBizSettings global, AyContext ct = null)
{
if (global == null)
{
//fetch or create as not provided (meaning this was called from Startup.cs)
global = ct.GlobalBizSettings.FirstOrDefault(z => z.Id == 1);
if (global == null)
{
global = new GlobalBizSettings();
ct.GlobalBizSettings.Add(global);
ct.SaveChanges();
}
}
//We have the object, now copy the static values here
SearchCaseSensitiveOnly = global.SearchCaseSensitiveOnly;
UseInventory = global.UseInventory;
TaxPartPurchaseId = global.TaxPartPurchaseId;
TaxPartSaleId = global.TaxPartSaleId;
TaxRateSaleId = global.TaxRateSaleId;
WorkOrderCompleteByAge=global.WorkOrderCompleteByAge;
}
}//eoc
}//eons