コード例 #1
0
 /// <summary>
 /// Given a queryId and list of keywords (strings), adds entries to the QueryKeywordJunction table.
 /// Throws an exception if QueryId not found for whatever reason.
 /// </summary>
 /// <param name="queryId">int Id of the query</param>
 /// <param name="keywords">list of string of keywords</param>
 /// <param name="kRepo">KeywordRepo</param>
 public void AddQueryKeywordJunction(int queryId, List <string> keywords, KeywordRepo kRepo)
 {
     if (!DBContainsQuery(queryId))
     {
         throw new DbUpdateException($"Query Id {queryId} not recognized.", new NotSupportedException());
     }
     foreach (var kw in keywords)
     {
         if (!kRepo.DBContainsKeyword(kw))
         {
             kRepo.AddKeyword(new Keyword()
             {
                 Word = kw
             });
         }
         _db.Add(new QueryKeywordJunction()
         {
             QueryId = queryId, Word = kw
         });
     }
 }
コード例 #2
0
        /// <summary>
        /// Given a queryId and list of keywords (strings), adds entries to the QueryKeywordJunction table.
        /// Throws an exception if QueryId not found for whatever reason.
        /// </summary>
        /// <param name="queryId">int Id of the query</param>
        /// <param name="keywords">list of string of keywords</param>
        /// <param name="kRepo">KeywordRepo</param>
        public async Task AddQueryKeywordJunctionAsync(int queryId, List <string> keywords, KeywordRepo kRepo)
        {
            var contains = await DBContainsQueryAsync(queryId);

            if (!contains)
            {
                throw new DbUpdateException($"Query Id {queryId} not recognized.", new NotSupportedException());
            }
            foreach (var kw in keywords)
            {
                contains = await kRepo.DBContainsKeywordAsync(kw);

                if (!contains)
                {
                    kRepo.AddKeyword(new Keyword()
                    {
                        Word = kw
                    });
                }
                _db.Add(new QueryKeywordJunction()
                {
                    QueryId = queryId, Word = kw
                });
            }
        }