Ejemplo n.º 1
0
        public ActionResult findVerse(SearchModel bible)
        {
            logger.Info("Entering BibleController.findVerse()");
            //checks if model is valid
            if (!ModelState.IsValid)
            {
                logger.Info("Model state is invalid");
                //if not, user is taken back to the search page
                return(View("Search"));
            }

            else
            {
                //call bible business service to find bible verse
                BibleBusinessService service = new BibleBusinessService();
                BibleModel           result  = service.findBibleVerse(bible);
                //user is taken to the search result page
                if (result != null)
                {
                    logger.Info("Exiting BibleController.createVerse() with search success");
                    return(View("SearchResult", result));
                }
                logger.Info("Exiting BibleController.createVerse() with search fail");
                //if no verse was found, user is taken back to the search page
                return(View("SearchResult"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult createVerse(BibleModel bible)
        {
            logger.Info("Entering BibleController.createVerse()");
            //checks if model is valid
            if (!ModelState.IsValid)
            {
                logger.Info("Model state is invalid");
                //if not, user is taken back to the add verse page
                return(View("AddVerse"));
            }

            else
            {
                //call bible business service to add bible verse
                BibleBusinessService service = new BibleBusinessService();
                //user is taken to a success page once bible verse has been added
                if (service.addVerse(bible))
                {
                    logger.Info("Exiting BibleController.createVerse() with entry success");
                    return(View("VerseSuccess"));
                }
            }
            //if failed to add bible verse, user is taken back to the bible entry page
            logger.Info("Exiting BibleController.createVerse() with entry fail");
            return(View("AddVerse"));
        }
Ejemplo n.º 3
0
        public void InsertBible(BibleModel bible)
        {
            Task <BibleModel> existing = BiblesData.database.Table <BibleModel>().FirstOrDefaultAsync(b => b.BibleName == bible.BibleName);

            if (existing.Result != null)
            {
                return;
            }

            BiblesData.database.InsertAsync(bible);
        }
Ejemplo n.º 4
0
        //method to add bible verse to database
        public bool addVerse(BibleModel bible)
        {
            try
            {
                // Setup SELECT query with parameters
                string query = "INSERT INTO dbo.Bible (testament, book, chapter, verseNo, verse) VALUES (@testament, @book, @chapter, @verseNo, @verse)";

                // Create connection and command
                using (SqlConnection cn = new SqlConnection(connectionString))
                    using (SqlCommand cmd = new SqlCommand(query, cn))
                    {
                        // Set query parameters and their values
                        cmd.Parameters.Add("@testament", SqlDbType.VarChar, 50).Value = bible.testament;
                        cmd.Parameters.Add("@book", SqlDbType.VarChar, 50).Value      = bible.bookName;
                        cmd.Parameters.Add("@chapter", SqlDbType.Int, 50).Value       = bible.chapterNo;
                        cmd.Parameters.Add("@verseNo", SqlDbType.Int, 50).Value       = bible.verseNo;
                        cmd.Parameters.Add("@verse", SqlDbType.VarChar, 3900).Value   = bible.verse;

                        // Open the connection
                        cn.Open();

                        int rowsAffected = cmd.ExecuteNonQuery();
                        cn.Close();

                        if (rowsAffected > 0)
                        {
                            return(true);
                        }
                    }
            }

            catch (SqlException e)
            {
                throw e;
            }

            return(false);
        }
Ejemplo n.º 5
0
        public static bool LoadBible(string path)
        {
            string bibleName = Path.GetFileNameWithoutExtension(path);

            BibleModel bibleModel = BiblesData.Database.GetBible(bibleName);

            if (bibleModel != null)
            {
                BiblesData.Database.DeleteBibleVerses(bibleModel.BiblesId);
                //return true;
            }

            bibleModel = new BibleModel
            {
                BiblesId  = 0,
                BibleName = bibleName
            };

            BiblesData.Database.InsertBible(bibleModel);

            BibleModel added = BiblesData.Database.GetBible(bibleName);

            while (added == null)
            {
                Sleep.ThreadWait(100);

                added = BiblesData.Database.GetBible(bibleName);
            }

            bibleModel.BiblesId = added.BiblesId;

            List <string> bibleVerses = new List <string>();

            List <BibleVerseModel> bulkList = new List <BibleVerseModel>();

            bibleVerses.AddRange(File.ReadAllLines(path));

            foreach (string verseLine in bibleVerses)
            {
                int breakIndex = verseLine.LastIndexOf("||") + 2;

                string verseKey = verseLine.Substring(0, breakIndex);

                string verseText = verseLine.Substring(breakIndex, verseLine.Length - breakIndex);

                BibleVerseModel verseModel = new BibleVerseModel
                {
                    BibleVerseKey = $"{bibleModel.BiblesId}||{verseKey}",
                    VerseText     = verseText
                };

                bulkList.Add(verseModel);
            }

            int skipIndex = 0;

            int takeValue = 500;

            try
            {
                while (skipIndex <= bulkList.Count)
                {
                    List <BibleVerseModel> addList = bulkList.Skip(skipIndex).Take(takeValue).ToList();

                    BiblesData.Database.InsertBibleVerseBulk(addList);

                    skipIndex += takeValue;

                    string checkKey = addList.Last().BibleVerseKey;

                    int waitIndex = 0;

                    while (BiblesData.Database.GetVerse(checkKey) == null)
                    {
                        Sleep.ThreadWait(200);

                        ++waitIndex;

                        if (waitIndex >= 20)
                        {
                            foreach (BibleVerseModel verseModel in addList)
                            {
                                BiblesData.Database.InsertBibleVerse(verseModel);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                throw;
            }

            return(true);
        }
Ejemplo n.º 6
0
        public async void LoadEmbeddedBibles(Dispatcher dispatcher, FontFamily defaultFont)
        {
            Task <List <BibleModel> > loadedBiles = BiblesData.Database.GetBibles();

            await Task.Run(() =>
            {
                try
                {
                    #region LOAD BIBLES

                    if (loadedBiles.Result.Count == 0)
                    {
                        foreach (string bible in bibleNames)
                        {
                            dispatcher.Invoke(() =>
                            {
                                this.InitialDataLoadCompleted?.Invoke(this, $"Loading...{bible}", false, null);
                            });

                            BibleModel bibleModel = loadedBiles.Result.FirstOrDefault(l => l.BibleName == bible);

                            if (bibleModel == null)
                            {
                                bibleModel = new BibleModel
                                {
                                    BiblesId  = 0,
                                    BibleName = bible
                                };

                                BiblesData.Database.InsertBible(bibleModel);

                                BibleModel added = BiblesData.Database.GetBible(bible);

                                while (added == null)
                                {
                                    Sleep.ThreadWait(100);

                                    added = BiblesData.Database.GetBible(bible);
                                }

                                bibleModel.BiblesId = added.BiblesId;
                            }

                            this.LoadBibleVerses(dispatcher, bibleModel);

                            if (bible == this.systemDefaultbible)
                            {
                                UserPreferenceModel userPref = new UserPreferenceModel
                                {
                                    DefaultBible     = bibleModel.BiblesId,
                                    Font             = defaultFont.ParseToString(),
                                    FontSize         = 12,
                                    SynchronizzeTabs = false,
                                    LanguageId       = 0,
                                    LastReadVerse    = $"{bibleModel.BiblesId}||01O||1||1||"
                                };

                                BiblesData.Database.InsertPreference(userPref);
                            }
                        }
                    }

                    #endregion

                    this.LoadStrongsConcordance(dispatcher);
                }
                catch (Exception err)
                {
                    dispatcher.Invoke(() =>
                    {
                        this.InitialDataLoadCompleted?.Invoke(this, string.Empty, false, err);
                    });
                }

                dispatcher.Invoke(() =>
                {
                    this.InitialDataLoadCompleted?.Invoke(this, string.Empty, true, null);
                });
            });
        }
Ejemplo n.º 7
0
        private void LoadBibleVerses(Dispatcher dispatcher, BibleModel bibleModel)
        {
            string bibleFormatName = bibleModel.BibleName
                                     .Replace(' ', '_')
                                     .Replace('-', '_');

            var bible = typeof(Properties.Resources)
                        .GetProperties(BindingFlags.Static | BindingFlags.NonPublic |
                                       BindingFlags.Public)
                        .Where(p => p.PropertyType == typeof(string) && p.Name == bibleFormatName)
                        .Select(x => new { Bible = x.GetValue(null, null) })
                        .FirstOrDefault();

            List <string> verses = bible.Bible
                                   .ParseToString()
                                   .Split(new char[] { '\n', '\r' }, System.StringSplitOptions.RemoveEmptyEntries)
                                   .ToList();


            List <BibleVerseModel> bulkList = new List <BibleVerseModel>();

            foreach (string verseLine in verses)
            {
                int breakIndex = verseLine.LastIndexOf("||") + 2;

                string verseKey = verseLine.Substring(0, breakIndex);

                string verseText = verseLine.Substring(breakIndex, verseLine.Length - breakIndex);

                BibleVerseModel verseModel = new BibleVerseModel
                {
                    BibleVerseKey = $"{bibleModel.BiblesId}||{verseKey}",
                    VerseText     = verseText
                };

                bulkList.Add(verseModel);
            }

            int skipIndex = 0;

            int takeValue = 500;

            while (skipIndex <= bulkList.Count)
            {
                List <BibleVerseModel> addList = bulkList.Skip(skipIndex).Take(takeValue).ToList();

                BiblesData.Database.InsertBibleVerseBulk(addList);

                skipIndex += takeValue;

                string checkKey = addList.Last().BibleVerseKey;

                int waitIndex = 0;

                while (BiblesData.Database.GetVerse(checkKey) == null)
                {
                    Sleep.ThreadWait(200);

                    ++waitIndex;

                    if (waitIndex >= 20)
                    {
                        dispatcher.Invoke(() =>
                        {
                            this.InitialDataLoadCompleted?.Invoke(this, $"Loading...{bibleModel.BibleName}", false, null);
                        });

                        foreach (BibleVerseModel verseModel in addList)
                        {
                            BiblesData.Database.InsertBibleVerse(verseModel);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        //method to add bible verse
        public bool addVerse(BibleModel bible)
        {
            BibleDataService service = new BibleDataService();

            return(service.addVerse(bible));
        }