예제 #1
0
 public static Description Create(Idiom idiom)
 {
     return new Description(idiom.Word, idiom.Definitions, idiom.Usages)
     {
         Type = "Idiom"
     };
 }
 public async Task<QueryResult> AddIdiom(Idiom idiom)
 {
     if (idiom == null)
         return QueryResult.EmptyField(nameof(idiom));
     if (!idiom.Validate())
         return QueryResult.InvalidField(nameof(idiom));
     if (!idiom.Usages.Any())
         return QueryResult.InvalidField(nameof(idiom));
     return QueryResult.QueryFailed(await Manager.AddIdiomAsync(idiom));
 }
예제 #3
0
 public async Task<bool> AddIdiomAsync(Idiom idiom)
 {
     if (!idiom.Validate() && !await Context.Idioms.ContainsAsync(idiom))
         return false;
     Context.Idioms.Add(idiom);
     bool buildPronounciation = string.IsNullOrEmpty(idiom.Pronunciation);
     foreach (char i in idiom.Word)
     {
         Character c = await Manager.FindCharacterAsync(i.ToString());
         idiom.Characters.Add(c);
         c.Idioms.Add(idiom);
         if (buildPronounciation)
             idiom.Pronunciation += c.Pronunciation;
     }
     await Save();
     return true;
 }