/**
  * 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()));
 }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
 /**
  * <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));
 }