This commit is contained in:
2020-12-23 15:42:39 +00:00
parent c0a90fffb0
commit 22ac0d9189
3 changed files with 69 additions and 27 deletions

View File

@@ -12,7 +12,7 @@ namespace AyaNova.Biz
internal class TranslationBiz : BizObject
{
internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
{
@@ -20,7 +20,7 @@ namespace AyaNova.Biz
UserId = currentUserId;
UserTranslationId = userTranslationId;
CurrentUserRoles = userRoles;
BizType = AyaType.Translation;
BizType = AyaType.Translation;
}
internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
@@ -335,7 +335,7 @@ namespace AyaNova.Biz
// Get subset for specified translation ID
// called from controller and Used when user is not logged in
// e.g. when resetting their password
//
// ## NOTE: NO other use for this other than the reset password at this point
internal static async Task<List<KeyValuePair<string, string>>> GetSpecifiedTranslationSubsetStaticAsync(List<string> param, long translationId)
{
#if (DEBUG)
@@ -371,6 +371,43 @@ namespace AyaNova.Biz
}
}
/////////////////////////////////////////////////////////////////
// Get subset for specified user (looks up translation id) statically
// called from internal code (e.g. notification processing)
//
internal static async Task<Dictionary<string, string>> GetSubsetForUserStaticAsync(List<string> param, long userId)
{
long translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
using (AyContext ct = ServiceProviderProvider.DBContext)
{
translationId = await ct.UserOptions.AsNoTracking().Where(z => z.UserId == userId).Select(z => z.TranslationId).SingleAsync();
}
return await GetSubsetStaticAsync(param, translationId);
}
/////////////////////////////////////////////////////////////////
// Get single item for specified user (looks up translation id) statically
// called from internal code (e.g. notification processing)
//
internal static async Task<string> GetTranslationForUserStaticAsync(string translationKey, long userId)
{
long translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
using (AyContext ct = ServiceProviderProvider.DBContext)
{
translationId = await ct.UserOptions.AsNoTracking().Where(z => z.UserId == userId).Select(z => z.TranslationId).SingleAsync();
}
var param = new List<string>() { translationKey };
var ret = await GetSubsetStaticAsync(param, translationId);
if (ret.Count > 0) return ret[translationKey];
return $"??{translationKey}";
}
//used by internal notification and other processes i.e. "Server" in all languages for server based notifications
internal static async Task<Dictionary<long, string>> GetAllTranslationsForKey(string translationKey)
{
@@ -394,28 +431,29 @@ namespace AyaNova.Biz
}
/// <summary>
/// Get the value of the key provided in the default translation chosen
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
internal static async Task<string> GetDefaultTranslationAsync(string key)
{
if (string.IsNullOrWhiteSpace(key))
return "ERROR: GetDefaultTranslation NO KEY VALUE SPECIFIED";
#if (DEBUG)
TrackRequestedKey(key);
#endif
using (AyContext ct = ServiceProviderProvider.DBContext)
return await ct.TranslationItem.Where(z => z.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && z.Key == key).Select(z => z.Display).AsNoTracking().FirstOrDefaultAsync();
}
//DEPRECATED
// /// <summary>
// /// Get the value of the key provided in the default translation chosen
// /// </summary>
// /// <param name="key"></param>
// /// <returns></returns>
// internal static async Task<string> GetDefaultTranslationAsync(string key)
// {
// if (string.IsNullOrWhiteSpace(key))
// return "ERROR: GetDefaultTranslation NO KEY VALUE SPECIFIED";
// #if (DEBUG)
// TrackRequestedKey(key);
// #endif
// using (AyContext ct = ServiceProviderProvider.DBContext)
// return await ct.TranslationItem.Where(z => z.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && z.Key == key).Select(z => z.Display).AsNoTracking().FirstOrDefaultAsync();
// }
//Get all stock keys that are valid (used for key coverage reporting)
internal static async Task<List<string>> GetKeyListAsync()
{
using (AyContext ct = ServiceProviderProvider.DBContext)
return await ct.TranslationItem.Where(z => z.TranslationId == 1).OrderBy(z => z.Key).Select(z => z.Key).AsNoTracking().ToListAsync();
}
// //Get all stock keys that are valid (used for key coverage reporting)
// internal static async Task<List<string>> GetKeyListAsync()
// {
// using (AyContext ct = ServiceProviderProvider.DBContext)
// return await ct.TranslationItem.Where(z => z.TranslationId == 1).OrderBy(z => z.Key).Select(z => z.Key).AsNoTracking().ToListAsync();
// }