This commit is contained in:
2018-10-03 19:32:35 +00:00
parent 57a62f9b86
commit 5a235dc77c
2 changed files with 47 additions and 26 deletions

View File

@@ -414,36 +414,44 @@ namespace AyaNova.Biz
//BUILD A LIST OF MatchingDictionaryEntry items FOR THE MATCHING WORDS //BUILD A LIST OF MatchingDictionaryEntry items FOR THE MATCHING WORDS
List<MatchingDictionaryEntry> MatchingKeywordIdList = new List<MatchingDictionaryEntry>(); List<MatchingDictionaryEntry> MatchingKeywordIdList = new List<MatchingDictionaryEntry>();
//ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS
var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word);
//Put the matching keyword ID's into the list
foreach (KeyValuePair<long, string> K in ExistingKeywordMatches)
{
bool IsName = false;
if (NameKeyWordList.Contains(K.Value))
IsName = true;
MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = K.Key, InName = IsName });
}
//ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S //######### FROM HERE NEEDS TO LOCK SEARCHDICTIONARY FROM HERE TO ADDING NEW WORDS
bool NewWordsAdded = false; using (var transaction = ct.Database.BeginTransaction())
var NewSearchDictionaryWordsList = new List<SearchDictionary>();
foreach (string KeyWord in KeyWordList)
{ {
if (!ExistingKeywordMatches.ContainsValue(KeyWord)) //ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS
var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word);
//Put the matching keyword ID's into the list
foreach (KeyValuePair<long, string> K in ExistingKeywordMatches)
{ {
NewSearchDictionaryWordsList.Add(new SearchDictionary() { Word = KeyWord }); bool IsName = false;
NewWordsAdded = true; if (NameKeyWordList.Contains(K.Value))
IsName = true;
MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = K.Key, InName = IsName });
} }
}
//Save the context in order to get the id's of the new words added //ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S
if (NewWordsAdded) bool NewWordsAdded = false;
{ var NewSearchDictionaryWordsList = new List<SearchDictionary>();
//adding in a range sped this up noticeably foreach (string KeyWord in KeyWordList)
ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList); {
ct.SaveChanges(); if (!ExistingKeywordMatches.ContainsValue(KeyWord))
} {
NewSearchDictionaryWordsList.Add(new SearchDictionary() { Word = KeyWord });
NewWordsAdded = true;
}
}
//Save the context in order to get the id's of the new words added
if (NewWordsAdded)
{
//adding in a range sped this up noticeably
ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList);
ct.SaveChanges();
}
transaction.Commit();
}//end transaction
//#########################
//----- //-----

View File

@@ -236,7 +236,20 @@ namespace raven_integration
var ErrorMessage = string.Empty; var ErrorMessage = string.Empty;
var ERR = a.ObjectResponse["error"]; var ERR = a.ObjectResponse["error"];
if (ERR != null) if (ERR != null)
ErrorMessage = ERR.Value<string>(); {
var ecode = ERR["code"];
if (ecode != null)
ErrorMessage += $"CODE: {ecode} ";
var emsg = ERR["message"];
if (emsg != null)
ErrorMessage += $"MESSAGE: {emsg} ";
var etarget = ERR["target"];
if (etarget != null)
ErrorMessage += $"TARGET: {etarget} ";
}
a.ObjectResponse["error"].Should().BeNull("because there should not be an error on an api call, error was: {0}", ErrorMessage); a.ObjectResponse["error"].Should().BeNull("because there should not be an error on an api call, error was: {0}", ErrorMessage);
a.ObjectResponse["result"].Should().NotBeNull("A result should be returned"); a.ObjectResponse["result"].Should().NotBeNull("A result should be returned");
} }