/// <summary>
 /// Creates search query
 /// </summary>
 /// <param name="query">search query</param>
 /// <returns></returns>
 public SearchQueryDB Add(SearchQueryDB query)
 {
     query.Id = Guid.NewGuid().ToString();
     _context.SearchQueries.Add(query);
     _context.SaveChanges();
     return(query);
 }
        /// <summary>
        /// Creates search query
        /// </summary>
        /// <param name="query">search query</param>
        /// <returns></returns>
        public SearchQueryDTO Add(SearchQueryDTO query)
        {
            SearchQueryDB queryDb = new SearchQueryDB()
            {
                Id = query.Id, Created = query.Date, Query = query.Query, UserId = query.UserId
            };

            return(_mapper.Map <SearchQueryDB, SearchQueryDTO>(_searchQueryDb.Add(queryDb)));
        }
        /// <summary>
        /// Creates search query async
        /// </summary>
        /// <param name="query">search query</param>
        /// <returns></returns>
        public async Task <Result <SearchQueryDTO> > AddAsync(SearchQueryDTO query)
        {
            SearchQueryDB queryDb = new SearchQueryDB()
            {
                Id = query.Id, Created = query.Date, Query = query.Query, UserId = query.UserId
            };
            var result = await _searchQueryDb.AddAsync(queryDb);

            return(result.IsSuccess ? Result <SearchQueryDTO> .Ok(_mapper.Map <SearchQueryDTO>(result.Data))
                : Result <SearchQueryDTO> .Fail <SearchQueryDTO>(result.Message));
        }
        /// <summary>
        /// Creates search query
        /// </summary>
        /// <param name="query">search query</param>
        /// <returns></returns>
        public async Task <Result <SearchQueryDB> > AddAsync(SearchQueryDB query)
        {
            try
            {
                query.Id      = Guid.NewGuid().ToString();
                query.Created = DateTime.Now;
                _context.SearchQueries.Add(query);
                await _context.SaveChangesAsync().ConfigureAwait(false);

                return(Result <SearchQueryDB> .Ok(query));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result <SearchQueryDB> .Fail <SearchQueryDB>($"Cannot save SearchQuery. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return(Result <SearchQueryDB> .Fail <SearchQueryDB>($"Cannot save SearchQuery. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return(Result <SearchQueryDB> .Fail <SearchQueryDB>($"Invalid SearchQuery. {e.Message}"));
            }
        }