//Add
 public static PreSearches AddPreSerch(PreSearches preSearch)
 {
     using (RatzhKatzviEntities1 db = new RatzhKatzviEntities1())
     {
         PreSearches isExist = db.PreSearches.FirstOrDefault(x => x.Id == preSearch.Id);
         if (isExist == null)
         {
             isExist = db.PreSearches.Add(preSearch);
             db.SaveChanges();
         }
         return(isExist);
     }
 }
 //Delete
 public static void DeletePreSerch(PreSearches preSearch)
 {
     if (preSearch != null)
     {
         using (RatzhKatzviEntities1 db = new RatzhKatzviEntities1())
         {
             try {
                 db.Entry(preSearch).State = EntityState.Modified;
                 db.PreSearches.Remove(preSearch);
                 db.SaveChanges();
             }
             catch (Exception ex) { }
         }
     }
 }
 //Update
 public static void UpdatePreSerches(PreSearches preSearches)
 {
     using (RatzhKatzviEntities1 db = new RatzhKatzviEntities1())
     {
         try
         {
             PreSearches isExist = db.PreSearches.FirstOrDefault(x => x.Id == preSearches.Id);
             if (isExist != null)
             {
                 db.Entry(preSearches).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
         catch (Exception ex) { }
     }
 }
        public static List <WordLocation> SearchInBooks(string text)
        {
            if (text.Length > 0)
            {
                string[] searchWords = text.Split(' ');
                string   newRgxText  = ".*";
                foreach (var word in searchWords)
                {
                    newRgxText += word + "(.*)";
                }
                var rgx = new Regex(newRgxText);

                List <Items>        items     = ItemsDL.GetAllItems().Where(item => true == item.EnableSearch).ToList();
                List <BookPages>    bookPages = new List <BookPages>();
                List <WordLocation> searchResultWordLocations = new List <WordLocation>();
                bool        flag         = false;
                PreSearches newPreSearch = new PreSearches();
                foreach (var item in items)
                {
                    bookPages = BookPagesDL.GetBookByItemId(item.ItemId);
                    bookPages = BookPagesDL.SearchText(bookPages, rgx);
                    if (bookPages.Count > 0)
                    {
                        if (!flag)
                        {
                            flag         = true;
                            newPreSearch = PreSearchesDL.AddPreSerch(new PreSearches {
                                PreSearch = text, SearchedCounter = 1
                            });
                        }
                        if (newPreSearch != default(PreSearches))
                        {
                            searchResultWordLocations.AddRange(WordLocationDL.Create_List_WordLocationFromBooPage(bookPages, newPreSearch.Id));
                        }
                    }
                }
                if (searchResultWordLocations != default(List <WordLocation>))
                {
                    WordLocationDL.AddList(searchResultWordLocations);
                }
                return(searchResultWordLocations);
            }
            return(new List <WordLocation>());
        }