This commit is contained in:
@@ -50,11 +50,11 @@ namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
//make sure sourceid exists
|
||||
if (!LocaleExists(inObj.Id))
|
||||
if (!await LocaleExistsAsync(inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Id", "Source locale id does not exist");
|
||||
|
||||
//Ensure name is unique and not too long and not empty
|
||||
ValidateAsync(inObj.Name, true);
|
||||
await ValidateAsync(inObj.Name, true);
|
||||
|
||||
if (HasErrors)
|
||||
return null;
|
||||
@@ -74,10 +74,10 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
//Add it to the context so the controller can save it
|
||||
ct.Locale.Add(NewLocale);
|
||||
await ct.Locale.AddAsync(NewLocale);
|
||||
await ct.SaveChangesAsync();
|
||||
//Log
|
||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, NewLocale.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, NewLocale.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||
return NewLocale;
|
||||
|
||||
}
|
||||
@@ -113,12 +113,12 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
#if (DEBUG)
|
||||
internal AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo LocaleKeyCoverage()
|
||||
internal async Task<AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo> LocaleKeyCoverageAsync()
|
||||
{
|
||||
AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo L = new AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo();
|
||||
L.RequestedKeys = ServerBootConfig.LocaleKeysRequested;
|
||||
L.RequestedKeys.Sort();
|
||||
var AllKeys = GetKeyList();
|
||||
var AllKeys = await GetKeyListAsync();
|
||||
foreach (string StockKey in AllKeys)
|
||||
{
|
||||
if (!L.RequestedKeys.Contains(StockKey))
|
||||
@@ -171,9 +171,9 @@ namespace AyaNova.Biz
|
||||
TrackRequestedKey(param);
|
||||
#endif
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
if (!LocaleExistsStatic(localeId, ct))
|
||||
if (!await LocaleExistsStaticAsync(localeId, ct))
|
||||
localeId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
var ret = await ct.LocaleItem.Where(x => x.LocaleId == localeId && param.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display);
|
||||
var ret = await ct.LocaleItem.Where(x => x.LocaleId == localeId && param.Contains(x.Key)).AsNoTracking().ToDictionaryAsync(x => x.Key, x => x.Display);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
if (ct == null)
|
||||
ct = ServiceProviderProvider.DBContext;
|
||||
var ret = await ct.Locale.Where(x => x.Id == localeId).Select(m => m.CjkIndex).SingleOrDefaultAsync();
|
||||
var ret = await ct.Locale.Where(x => x.Id == localeId).AsNoTracking().Select(m => m.CjkIndex).SingleOrDefaultAsync();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -201,14 +201,14 @@ namespace AyaNova.Biz
|
||||
TrackRequestedKey(key);
|
||||
#endif
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
return await ct.LocaleItem.Where(m => m.LocaleId == ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID && m.Key == key).Select(m => m.Display).FirstOrDefaultAsync();
|
||||
return await ct.LocaleItem.Where(m => m.LocaleId == ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID && m.Key == key).Select(m => m.Display).AsNoTracking().FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
//Get all stock keys that are valid (used for import)
|
||||
internal static List<string> GetKeyList()
|
||||
internal static async Task<List<string>> GetKeyListAsync()
|
||||
{
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
return ct.LocaleItem.Where(m => m.LocaleId == 1).OrderBy(m => m.Key).Select(m => m.Key).ToList();
|
||||
return await ct.LocaleItem.Where(m => m.LocaleId == 1).OrderBy(m => m.Key).Select(m => m.Key).AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ namespace AyaNova.Biz
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
||||
|
||||
ValidateAsync(dbObj.Name, false);
|
||||
await ValidateAsync(dbObj.Name, false);
|
||||
|
||||
if (HasErrors)
|
||||
return false;
|
||||
@@ -281,13 +281,14 @@ namespace AyaNova.Biz
|
||||
//DELETE
|
||||
//
|
||||
|
||||
internal bool Delete(Locale dbObj)
|
||||
internal async Task<bool> DeleteAsync(Locale dbObj)
|
||||
{
|
||||
//Determine if the object can be deleted, do the deletion tentatively
|
||||
ValidateCanDeleteAsync(dbObj);
|
||||
await ValidateCanDeleteAsync(dbObj);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.Locale.Remove(dbObj);
|
||||
await ct.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -310,7 +311,7 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 char max");
|
||||
|
||||
//Name must be unique
|
||||
if( await ct.Locale.AnyAsync(m => m.Name == inObjName))
|
||||
if (await ct.Locale.AnyAsync(m => m.Name == inObjName))
|
||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
||||
|
||||
return;
|
||||
@@ -348,51 +349,51 @@ namespace AyaNova.Biz
|
||||
//UTILITIES
|
||||
//
|
||||
|
||||
public long LocaleNameToId(string localeName)
|
||||
public async Task<long> LocaleNameToIdAsync(string localeName)
|
||||
{
|
||||
var v = ct.Locale.Where(c => c.Name == localeName).Select(x => x.Id);
|
||||
if (v.Count() < 1) return 0;
|
||||
return v.First();
|
||||
var v = await ct.Locale.AsNoTracking().FirstOrDefaultAsync(c => c.Name == localeName);
|
||||
if (v == null) return 0;
|
||||
return v.Id;
|
||||
}
|
||||
|
||||
public static long LocaleNameToIdStatic(string localeName, AyContext ct = null)
|
||||
public static async Task<long> LocaleNameToIdStaticAsync(string localeName, AyContext ct = null)
|
||||
{
|
||||
if (ct == null)
|
||||
{
|
||||
ct = ServiceProviderProvider.DBContext;
|
||||
}
|
||||
var v = ct.Locale.Where(c => c.Name == localeName).Select(x => x.Id);
|
||||
if (v.Count() < 1) return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
return v.First();
|
||||
var v = await ct.Locale.AsNoTracking().FirstOrDefaultAsync(c => c.Name == localeName);
|
||||
if (v == null) return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
return v.Id;
|
||||
}
|
||||
|
||||
public bool LocaleExists(string localeName)
|
||||
public async Task<bool> LocaleExistsAsync(string localeName)
|
||||
{
|
||||
return LocaleNameToId(localeName) != 0;
|
||||
return await LocaleNameToIdAsync(localeName) != 0;
|
||||
}
|
||||
|
||||
public bool LocaleExists(long id)
|
||||
public async Task<bool> LocaleExistsAsync(long id)
|
||||
{
|
||||
return ct.Locale.Any(e => e.Id == id);
|
||||
return await ct.Locale.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
|
||||
public static bool LocaleExistsStatic(long id, AyContext ct)
|
||||
public static async Task<bool> LocaleExistsStaticAsync(long id, AyContext ct)
|
||||
{
|
||||
return ct.Locale.Any(e => e.Id == id);
|
||||
return await ct.Locale.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
|
||||
public static long EnsuredLocaleIdStatic(long id, AyContext ct)
|
||||
public static async Task<long> EnsuredLocaleIdStaticAsync(long id, AyContext ct)
|
||||
{
|
||||
if (!ct.Locale.Any(e => e.Id == id))
|
||||
if (!await ct.Locale.AnyAsync(e => e.Id == id))
|
||||
return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
return id;
|
||||
}
|
||||
|
||||
public bool LocaleItemExists(long id)
|
||||
public async Task<bool> LocaleItemExistsAsync(long id)
|
||||
{
|
||||
return ct.LocaleItem.Any(e => e.Id == id);
|
||||
return await ct.LocaleItem.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
|
||||
@@ -478,23 +479,23 @@ namespace AyaNova.Biz
|
||||
/// Ensure stock locales and setup defaults
|
||||
/// Called by boot preflight check code AFTER it has already ensured the locale is a two letter code if stock one was chosen
|
||||
/// </summary>
|
||||
public void ValidateLocales()
|
||||
public async Task ValidateLocalesAsync()
|
||||
{
|
||||
//Ensure default locales are present and that there is a server default locale that exists
|
||||
|
||||
if (!LocaleExists("en"))
|
||||
if (!await LocaleExistsAsync("en"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale English (en) not found in database!");
|
||||
}
|
||||
if (!LocaleExists("es"))
|
||||
if (!await LocaleExistsAsync("es"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale Spanish (es) not found in database!");
|
||||
}
|
||||
if (!LocaleExists("de"))
|
||||
if (!await LocaleExistsAsync("de"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale German (de) not found in database!");
|
||||
}
|
||||
if (!LocaleExists("fr"))
|
||||
if (!await LocaleExistsAsync("fr"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale French (fr) not found in database!");
|
||||
}
|
||||
@@ -508,7 +509,7 @@ namespace AyaNova.Biz
|
||||
case "fr":
|
||||
break;
|
||||
default:
|
||||
if (!LocaleExists(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE))
|
||||
if (!await LocaleExistsAsync(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale {ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE} not found in database!");
|
||||
}
|
||||
@@ -517,14 +518,16 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
//Put the default locale ID number into the ServerBootConfig for later use
|
||||
ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID = LocaleNameToId(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE);
|
||||
ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID = await LocaleNameToIdAsync(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// IMPORT v7 implementation
|
||||
public async Task<bool> ImportV7Async(JObject j, List<ImportAyaNova7MapItem> importMap, Guid jobId, Dictionary<string, Dictionary<Guid, string>> tagLists)
|
||||
public async Task<bool> ImportV7Async(
|
||||
JObject j, List<ImportAyaNova7MapItem> importMap,
|
||||
Guid jobId, Dictionary<string, Dictionary<Guid, string>> tagLists)
|
||||
{
|
||||
//some types need to import from more than one source hence the seemingly redundant switch statement for futureproofing
|
||||
switch (j["IMPORT_TASK"].Value<string>())
|
||||
@@ -538,7 +541,7 @@ namespace AyaNova.Biz
|
||||
var SourceLocaleName = v.Groups[1].ToString();
|
||||
|
||||
//Ensure doesn't already exist
|
||||
if (LocaleExists(SourceLocaleName))
|
||||
if (await LocaleExistsAsync(SourceLocaleName))
|
||||
{
|
||||
//If there are any validation errors, log in joblog and move on
|
||||
JobsBiz.LogJob(jobId, $"LocaleBiz::ImportV7Async -> - Locale \"{SourceLocaleName}\" already exists in database, can not import over an existing locale", ct);
|
||||
@@ -552,7 +555,7 @@ namespace AyaNova.Biz
|
||||
SkipKeys.Add("V7_TYPE");
|
||||
SkipKeys.Add("IMPORT_TASK");
|
||||
|
||||
List<string> ValidKeys = GetKeyList();
|
||||
List<string> ValidKeys = await GetKeyListAsync();
|
||||
Dictionary<string, string> NewLocaleDict = new Dictionary<string, string>();
|
||||
foreach (var Pair in j.Children())
|
||||
{
|
||||
@@ -587,7 +590,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
if (!NewLocaleDict.ContainsKey(s))
|
||||
{
|
||||
NewLocaleDict.Add(s, GetDefaultLocalizedTextAsync(s).Result);
|
||||
NewLocaleDict.Add(s, await GetDefaultLocalizedTextAsync(s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,18 +610,18 @@ namespace AyaNova.Biz
|
||||
l.LocaleItems.Add(new LocaleItem() { Key = K.Key, Display = K.Value });
|
||||
}
|
||||
|
||||
ct.Locale.Add(l);
|
||||
ct.SaveChanges();
|
||||
await ct.Locale.AddAsync(l);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log now that we have the Id, note that there is no source created / modified for this so just attributing to current userId
|
||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, l.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, l.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//just to hide compiler warning for now
|
||||
await Task.CompletedTask;
|
||||
|
||||
|
||||
//this is the equivalent of returning void for a Task signature with nothing to return
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user