示例#1
0
 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)));
 }
示例#2
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);
        }