Example #1
0
        private void SetRhymes()
        {
            if (LinesEndings.Count == 0)
            {
                return;
            }

            char mark = 'A';

            int index = 0;

            List <int> observedLines = new List <int>();

            while (index < LinesEndings.Count)
            {
                if (_linesEndings[index] == "")
                {
                    observedLines.Clear();
                    _rhymes.Add(' ');
                    mark = 'A';
                    index++;
                    continue;
                }

                _rhymes.Add('?');

                foreach (int observedIndex in observedLines)
                {
                    if (VerseModel.DoesItRhyme(_linesEndings[index], _linesEndings[observedIndex]) == Rhyme.FEMININE)
                    {
                        if (_rhymes[observedIndex] != '?')
                        {
                            _rhymes[index] = _rhymes[observedIndex];
                        }
                        else
                        {
                            _rhymes[observedIndex] = mark;
                            _rhymes[index]         = mark;
                            mark += (char)1;
                        }
                    }
                    else if (VerseModel.DoesItRhyme(_linesEndings[index], _linesEndings[observedIndex]) == Rhyme.MASCULINE)
                    {
                        if (_rhymes[observedIndex] != '?')
                        {
                            _rhymes[index] = _rhymes[observedIndex];
                        }
                        else
                        {
                            _rhymes[observedIndex] = char.ToLower(mark);
                            _rhymes[index]         = char.ToLower(mark);
                            mark += (char)1;
                        }
                    }
                }

                observedLines.Add(index);
                index++;
            }
        }
        public ActionResult CreateVerse(VerseModel v)
        {
            logger.Info("Entering VerseController.CreateVerse() with " + v);
            if (ModelState.IsValid)
            {
                VerseBusinessService bs = new VerseBusinessService();
                bool   result           = bs.CreateVerse(v);
                string message;
                if (result)
                {
                    message = "Verse successfully inserted";
                }
                else
                {
                    message = "Verse insertion failed.";
                }

                logger.Info("Exiting VerseController.CreateVerse() with " + message);
                return(View("Index"));
            }
            else
            {
                return(View());
            }
        }
Example #3
0
 //Initialized
 public DAO(VerseModel model)
 {
     testament = model.Testament;
     book      = model.Book;
     chapter   = model.Chapter;
     verse     = model.Verse;
     text      = model.Text;
 }
Example #4
0
        public VerseModel SearchVerse(VerseModel v)
        {
            logger.Info("Entering VerseBusinessService.SearchVerse() with " + v);
            VerseDataService ds     = new VerseDataService();
            VerseModel       result = ds.Read(v);

            logger.Info("Exiting VerseBusinessService.SearchVerse() with " + result);
            return(result);
        }
Example #5
0
        public bool CreateVerse(VerseModel v)
        {
            logger.Info("Entering VerseBusinessService.CreateVerse() with " + v);
            VerseDataService ds     = new VerseDataService();
            bool             result = ds.Create(v);

            logger.Info("Exiting VerseBusinessService.CreateVerse() with " + result);
            return(result);
        }
Example #6
0
        //Constructor sets class variables to the model traits and sets the connection.
        public VerseDAO(VerseModel model)
        {
            testament = model.Testament;
            book      = model.Book;
            chapter   = model.Chapter;
            verse     = model.Verse;
            text      = model.Text;

            conn = new SqlConnection(connString);
        }
Example #7
0
        public ActionResult Search(VerseModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Search"));
            }
            VerseService  vs   = new VerseService(model);
            List <string> text = vs.SearchVerses();

            return(View("SearchResults", text));
        }
Example #8
0
        public ActionResult Insert(VerseModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            VerseService vs = new VerseService(model);

            vs.InsertVerse();
            return(View());
        }
Example #9
0
 public ActionResult Insert(VerseModel model)
 {
     if (verseService.CreateVerse(model))
     {
         return(View("AddedVerse"));
     }
     else
     {
         return(View("AddFailed"));
     }
 }
Example #10
0
        private VerseModel buildVerse(XElement verse)
        {
            VerseModel vm = new VerseModel(verse.Attribute("unit-id").Value.ToString());

            vm.verseHeader = (string)verse.Element("heading");
            vm.verseNumber = Int32.Parse(verse.Element("verse-num").Value);
            vm.cssClass    = getCssClass(vm.unitId);

            vm.verseText = getVerseText(verse);

            return(vm);
        }
Example #11
0
        public ActionResult Search(VerseModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index"));
            }

            VerseService  service = new VerseService(model);
            List <string> text    = service.SearchVerses();

            return(View("Results", text));
        }
Example #12
0
        private void SetLinesEndingsAndNumbersOfSyllables()
        {
            if (!string.IsNullOrWhiteSpace(Text))
            {
                var lines = Text.Split('\n');

                for (int i = 0; i < lines.Length; i++)
                {
                    _linesEndings.Add(VerseModel.GetLastSyllables(lines[i]));
                    _numbersOfSyllables.Add(VerseModel.NumberOfSyllables(lines[i]));
                }
            }
        }
Example #13
0
        public ActionResult Insert(VerseModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Message = "This verse was already added previously!";
                return(View("Index"));
            }

            VerseService service = new VerseService(model);

            service.InsertVerse();
            ViewBag.Message = "You have added: " + model.Book + " " + model.Chapter + ":" + model.Verse + " to the app!";
            return(View("Index"));
        }
Example #14
0
        /**
         * <see>BibleVerseApp.Data.VerseDataInterface.GetById</see>
         */
        public VerseModel GetById(int Id)
        {
            MyLogger.GetInstance().Info("Entering VerseDAO.GetById \n With Parameter: " + Id);
            VerseModel Verse = null;

            //Create SQL Statment
            string SqlStatment = "SELECT * FROM dbo.Verse WHERE Id = @Id";

            //Create connection to the database
            using (SqlConnection connection = new SqlConnection(Connection))
            {
                //Create the command with the statment and connection
                SqlCommand sqlCommand = new SqlCommand(SqlStatment, connection);

                //Add parameters to the sql statment
                sqlCommand.Parameters.AddWithValue("@Id", Id);

                try
                {
                    //Opends connection
                    connection.Open();

                    //Runs the command
                    SqlDataReader reader = sqlCommand.ExecuteReader();

                    //With all the rows returned creates Verse Objects and adds them to a list
                    while (reader.Read())
                    {
                        Verse = new VerseModel {
                            Id        = (int)reader[0],
                            Testament = (string)reader[1],
                            Book      = (string)reader[2],
                            ChapNum   = (int)reader[3],
                            VerseNum  = (int)reader[4],
                            Text      = (string)reader[5]
                        };
                    }
                }
                catch (Exception ex)
                {
                    //If there is an error it will be logged to the log file and console
                    MyLogger.GetInstance().Error("SQL Error within VerseDAO.GetById \n With Error Message: " + ex.Message);
                    Console.WriteLine("SQL Error within ProductsDAO.GetAll(): " + ex.Message);
                }
            }

            //Return the list of Verses
            MyLogger.GetInstance().Info("Leaving VerseDAO.GetById \n With Parameter: " + Verse.ToString());
            return(Verse);
        }
        public ActionResult SearchVerse(VerseModel v)
        {
            logger.Info("Entering VerseController.SearchVerse() with " + v);
            if (ModelState.IsValid)
            {
                VerseBusinessService bs     = new VerseBusinessService();
                VerseModel           result = bs.SearchVerse(v);

                logger.Info("Exiting VerseController.OnSearchVerse() with " + result);
                return(View("~/Views/Verse/SearchResult.cshtml", result));
            }
            else
            {
                return(View());
            }
        }
        //method which accesses the SearchService utility and dependent on the value received will sets the
        //model values to the coresponding values.
        public ActionResult Search(VerseModel model)
        {
            logger = new MyLogger();
            SearchService service = new SearchService();

            if (service.Authenticate(model))
            {
                logger.Info("The given credentials returned a verse which exists in the database: " + model.Testament + "|" + model.Book + "|" + model.Chapter + "|" + model.Verse + "|" + model.VerseText);
                model = service.changeValues(model);
                return(View("~/Views/Search/Search.cshtml", model));
            }
            else
            {
                logger.Info("The given credentials did not exist in the database.");
                model.SearchStatus = 2;
                return(View("~/Views/Search/Search.cshtml", model));
            }
        }
        //creates the verse using the input fields from the form and inputs them to the database.
        public bool CreateVerse(VerseModel verse)
        {
            string connectionString = "Server =.; Database = BibleVerses; Trusted_Connection = True";
            string query            = @"insert into dbo.Verses(Testament,Book,Chapter,VerseNum,VerseText) VALUES (@Testament,@Book,@Chapter,@Verse,@VerseText)";
            bool   results          = false;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    SqlCommand command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Testament", verse.Testament);
                    command.Parameters.AddWithValue("@Book", verse.Book);
                    command.Parameters.AddWithValue("@Chapter", verse.Chapter);
                    command.Parameters.AddWithValue("@Verse", verse.Verse);
                    command.Parameters.AddWithValue("@VerseText", verse.VerseText);


                    command.Connection.Open();
                    int x = command.ExecuteNonQuery();
                    if (x < 0)
                    {
                        throw new Exception();
                    }
                    else
                    {
                        logger.Info("Connection to DB successful. Added the following verse : Testaments: " + verse.Testament + " Book: " + verse.Book + " Chapter: " + verse.Chapter + " Verse Number: " + verse.Verse + " Verse Text: " + verse.VerseText);
                        logger.Info("Verse was added.");
                        results = true;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
                finally
                {
                    logger.Info("Closing DB connection");
                    connection.Close();
                }
            }

            return(results);
        }
        //method which locates the given verse credentials and sets the model to the values from the database
        public VerseModel setToFoundVerse(VerseModel verse)
        {
            VerseModel foundVerse        = new VerseModel();
            string     conncectionString = "Data Source=DESKTOP-BEPLE8D;Initial Catalog=BibleVerses;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            string     query             = @"Select * from dbo.Verses WHERE dbo.Verses.Testament =" + "'" + verse.Testament + "'" + "AND dbo.Verses.Book = " + "'" + verse.Book + "'" + "AND dbo.Verses.Chapter =" + "'" + verse.Chapter + "'" + "AND dbo.Verses.VerseNum =" + "'" + verse.Verse + "'";

            using (SqlConnection connection = new SqlConnection(conncectionString))
            {
                try
                {
                    SqlCommand command = new SqlCommand(query, connection);
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            string foo = reader.GetString(1);
                            if (reader.GetString(1).Equals(verse.Testament) && reader.GetString(2).Equals(verse.Book) && reader.GetInt32(3).Equals(verse.Chapter) && reader.GetInt32(4).Equals(verse.Verse))
                            {
                                foundVerse.Testament    = reader.GetString(1);
                                foundVerse.Book         = reader.GetString(2);
                                foundVerse.Chapter      = reader.GetInt32(3);
                                foundVerse.Verse        = reader.GetInt32(4);
                                foundVerse.VerseText    = reader.GetString(5);
                                foundVerse.SearchStatus = 1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

            return(foundVerse);
        }
Example #19
0
        public void SetVerse(string bibleVerseKey)
        {
            try
            {
                if (bibleVerseKey.IsNullEmptyOrWhiteSpace())
                {
                    bibleVerseKey = "01O||1||1";
                }

                string bookKey = $"{Formatters.GetBookFromKey(bibleVerseKey)}||";

                string chapterKey = $"{bookKey}{Formatters.GetChapterFromKey(bibleVerseKey)}||";

                string verseKey = $"{chapterKey}{Formatters.GetVerseFromKey(bibleVerseKey)}||";

                if (Formatters.IsOldTestament(bibleVerseKey))
                {
                    BookModel book = this.OldTestamentBooks.FirstOrDefault(b => b.BookKey == bookKey);

                    this.SelectedOldTestamentBook = book;
                }
                else
                {
                    BookModel book = this.NewTestamentBooks.FirstOrDefault(b => b.BookKey == bookKey);

                    this.SelectedNewTestamentBook = book;
                }

                ChapterModel chapter = this.bookChapters.FirstOrDefault(c => c.ChapterKey == chapterKey);

                this.SelectedChapter = chapter;

                VerseModel verse = this.ChapterVerses.FirstOrDefault(v => v.VerseKey == verseKey);

                this.SelectedVerse = verse;
            }
            catch
            {
                // DO NOTHING, We would not like to have things fall over
            }
        }
Example #20
0
        /**
         * <see>BibleVerseApp.Data.VerseDataInterface.Insert</see>
         */
        public int Insert(VerseModel Verse)
        {
            MyLogger.GetInstance().Info("Entering VerseDAO.Insert \n With Parameter: " + Verse.ToString());
            int result = -1;

            //Creates a SQL Statment
            string SqlStatment = "INSERT INTO dbo.Verse (TESTAMENT, BOOK, CHAPTER_NUM, VERSE_NUM, VERSE_TEXT) VALUES (@Testament, @Book, @ChapNum, @VerseNum, @Text)";

            //Creates a connection to the database
            using (SqlConnection connection = new SqlConnection(Connection))
            {
                //Create the command to run the sql statment with the conneciton
                SqlCommand command = new SqlCommand(SqlStatment, connection);

                //Adds all parameters in to the command
                command.Parameters.AddWithValue("@Testament", Verse.Testament);
                command.Parameters.AddWithValue("@Book", Verse.Book);
                command.Parameters.AddWithValue("@ChapNum", Verse.ChapNum);
                command.Parameters.AddWithValue("@VerseNum", Verse.VerseNum);
                command.Parameters.AddWithValue("@Text", Verse.Text);

                try
                {
                    //Opens the connection
                    connection.Open();

                    //Runs the command on the database
                    result = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    //If there is an error it will be logged in the log file and the console
                    MyLogger.GetInstance().Error("SQL Error within VerseDAO.Insert \n With Error Message: " + ex.Message);
                    Console.WriteLine("SQL Error within ProductsDAO.GetAll(): " + ex.Message);
                }
            }

            //Return the number of rows affected
            MyLogger.GetInstance().Info("Leaving VerseDAO.Insert \n With Parameter: " + Verse.ToString());
            return(result);
        }
Example #21
0
        /**
         * <see>BibleVerseApp.Data.VerseDataInterface.Update</see>
         */
        public VerseModel Update(VerseModel Verse)
        {
            MyLogger.GetInstance().Info("Entering VerseDAO.Update \n With Parameter: " + Verse.ToString());
            int newIdNumber = -1;

            //Creates SQL Statment
            string SqlStatment = "UPDATE dbo.Verse SET TESTAMENT = @Testament, BOOK = @Book, CHAPTER_NUM = @ChapNum, VERSE_NUM = @VerseNum, VERSE_TEXT = @Text WHERE Id = @id";

            //Creates connection to the databse
            using (SqlConnection connection = new SqlConnection(Connection))
            {
                //Creates a command with the statment and connections
                SqlCommand sqlCommand = new SqlCommand(SqlStatment, connection);

                //Adds Parameters to the command
                sqlCommand.Parameters.AddWithValue("@Testament", Verse.Testament);
                sqlCommand.Parameters.AddWithValue("@Book", Verse.Book);
                sqlCommand.Parameters.AddWithValue("@ChapNum", Verse.ChapNum);
                sqlCommand.Parameters.AddWithValue("@VerseNum", Verse.VerseNum);
                sqlCommand.Parameters.AddWithValue("@Text", Verse.Text);

                try
                {
                    //Opens the connection
                    connection.Open();

                    newIdNumber = Convert.ToInt32(sqlCommand.ExecuteScalar());
                }
                catch (Exception ex)
                {
                    //If there is an error it will be logged to the lof file and console
                    MyLogger.GetInstance().Error("SQL Error within VerseDAO.Update \n With Error Message: " + ex.Message);
                    Console.WriteLine("SQL Error within ProductsDAO.GetAll(): " + ex.Message);
                }
            }

            MyLogger.GetInstance().Info("Leaving VerseDAO.Update \n With Parameter: " + Verse.ToString());
            return(Verse);
        }
        public VerseModel Read(VerseModel verse)
        {
            logger.Info("Entering VerseDataService.Read() with " + verse);

            VerseModel result = new VerseModel();

            string queryString = "SELECT * FROM dbo.verses WHERE (TESTAMENT LIKE @TESTAMENT) AND (BOOK LIKE @BOOK) AND (CHAPTER LIKE @CHAPTER) AND (VERSE LIKE @VERSE)";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.Add("@TESTAMENT", System.Data.SqlDbType.VarChar, 40).Value = "%" + verse.Testament + "%";
                command.Parameters.Add("@BOOK", System.Data.SqlDbType.VarChar, 40).Value      = "%" + verse.Book + "%";
                command.Parameters.Add("@CHAPTER", System.Data.SqlDbType.VarChar, 40).Value   = "%" + verse.Chapter + "%";
                command.Parameters.Add("@VERSE", System.Data.SqlDbType.VarChar, 40).Value     = "%" + verse.Verse + "%";

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        reader.Read();
                        result = new VerseModel(reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5));
                    }
                    reader.Close();
                    connection.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            logger.Info("Exiting VerseDataService.Read() with " + result);
            return(result);
        }
        public bool Create(VerseModel verse)
        {
            logger.Info("Entering VerseDataService.Create() with " + verse);

            bool success = false;

            string queryString = "INSERT INTO dbo.verses (TESTAMENT, BOOK, CHAPTER, VERSE, TEXT) VALUES (@TESTAMENT, @BOOK, @CHAPTER, @VERSE, @TEXT)";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.Add("@TESTAMENT", System.Data.SqlDbType.VarChar, 40).Value = verse.Testament;
                command.Parameters.Add("@BOOK", System.Data.SqlDbType.VarChar, 40).Value      = verse.Book;
                command.Parameters.Add("@CHAPTER", System.Data.SqlDbType.VarChar, 40).Value   = verse.Chapter;
                command.Parameters.Add("@VERSE", System.Data.SqlDbType.VarChar, 40).Value     = verse.Verse;
                command.Parameters.Add("@TEXT", System.Data.SqlDbType.VarChar, 1000).Value    = verse.Text;

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.RecordsAffected > 0)
                    {
                        success = true;
                    }
                    reader.Close();
                    connection.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            logger.Info("Exiting VerseDataService.Create() with " + success);
            return(success);
        }
 /**
  * VerseController.ProccessCreate
  *
  * <summary>Method called once a form was submited to add a verse</summary>
  *
  * <param>Verse - VerseModel: model containing all the properties of a verse</param>
  *
  * <returns>Index Page with the updated list of verses</returns>
  */
 public IActionResult ProcessCreate(VerseModel Verse)
 {
     MyLogger.GetInstance().Info("Entering VerseController.ProcessCreate: \n With Paramenter: " + Verse.ToString());
     VerseService.Insert(Verse);
     return(View("Index", VerseService.Get()));
 }
Example #25
0
        //method which calls the DAO function to set the values and return the verse object
        public VerseModel changeValues(VerseModel verse)
        {
            SearchDAO searchService = new SearchDAO();

            return(searchService.setToFoundVerse(verse));
        }
Example #26
0
        //method which calls the DAO function to find if the given verse is valid and return a true or false
        public bool Authenticate(VerseModel verse)
        {
            SearchDAO searchService = new SearchDAO();

            return(searchService.findByVerse(verse));
        }
Example #27
0
 public VerseService(VerseModel model)
 {
     dao = new DAO(model);
 }
Example #28
0
 //This constructor just instantiates the VerseDAO object
 public VerseService(VerseModel model)
 {
     //The VerseDAO requires the model, so it's just pushed through here.
     vd = new VerseDAO(model);
 }
 /**
  * <see>Busniess.VerseBusinessInterface.Update</see>
  */
 public VerseModel Update(VerseModel Verse)
 {
     MyLogger.GetInstance().Info("Entering VerseBusinessService.Update: \n With Parameter: " + Verse.ToString());
     return(VerseService.Update(Verse));
 }
 public bool Update(VerseModel verse)
 {
     throw new NotImplementedException();
 }