This commit is contained in:
@@ -144,13 +144,31 @@ namespace AyaNova.Biz
|
||||
t.CjkIndex = (bool)o["CjkIndex"];
|
||||
t.Stock = false;
|
||||
|
||||
int ExpectedKeyCount = await ct.TranslationItem.CountAsync(z => z.TranslationId == 1);
|
||||
Translation sample = await ct.Translation.Include(z => z.TranslationItems).SingleOrDefaultAsync(z => z.Id == 1);
|
||||
|
||||
JArray tItems=(JArray)o["TranslationItems"];
|
||||
if(tItems.Count() < ExpectedKeyCount ){
|
||||
AddError(ApiErrorCode.VALIDATION_FAILED,null, "Not enough");
|
||||
return false;
|
||||
}
|
||||
int ExpectedKeyCount = sample.TranslationItems.Count();
|
||||
JArray tItems = (JArray)o["TranslationItems"];
|
||||
if (tItems.Count() < ExpectedKeyCount)
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_FAILED, null, $"TranslationItems incomplete, expected {ExpectedKeyCount} but found {tItems.Count()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (JObject j in tItems)
|
||||
{
|
||||
var key = (string)j["Key"];
|
||||
var display = (string)j["Display"];
|
||||
if (null == sample.TranslationItems.Where(z => z.Key == key).FirstOrDefault())
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, null, $"TranslationItems key {key} is not valid");
|
||||
return false;
|
||||
}
|
||||
t.TranslationItems.Add(new TranslationItem { Key = key, Display = display });
|
||||
}
|
||||
|
||||
await ct.Translation.AddAsync(t);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, t.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user