/// <summary>
        /// method to add a new firearm
        /// </summary>
        /// <param name="firearm"></param>
        public void Insert(Firearm firearm)
        {
            string connString = GetConnectionString();

            // build out SQL command
            var sb = new StringBuilder("INSERT INTO Firearms");

            sb.Append(" ([ID],[Name],[Manufacturer], [FirearmType], [AmmoType], [BarrelLength])");
            sb.Append(" Values (");
            sb.Append("'").Append(firearm.ID).Append("',");
            sb.Append("'").Append(firearm.Name).Append("',");
            sb.Append("'").Append(firearm.Manufacturer).Append("',");
            sb.Append("'").Append(firearm.FirearmType).Append("',");
            sb.Append("'").Append(firearm.AmmoType).Append("',");
            sb.Append("'").Append(firearm.BarrelLength).Append("')");
            string sqlCommandString = sb.ToString();

            using (SqlConnection sqlConn = new SqlConnection(connString))
                using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
                {
                    try
                    {
                        sqlConn.Open();
                        sqlAdapter.InsertCommand = new SqlCommand(sqlCommandString, sqlConn);
                        sqlAdapter.InsertCommand.ExecuteNonQuery();
                    }
                    catch (SqlException sqlEx)
                    {
                        Console.WriteLine("SQL Exception: {0}", sqlEx.Message);
                        Console.WriteLine(sqlCommandString);
                    }
                }
        }
        /// <summary>
        /// method to update an existing ski run
        /// </summary>
        /// <param name="firearm">firearm object</param>
        public void Update(Firearm firearm)
        {
            string connString = GetConnectionString();

            // build out SQL command
            var sb = new StringBuilder("UPDATE Firearms SET ");

            sb.Append("Name = '").Append(firearm.Name).Append("', ");
            sb.Append("Manufacturer = '").Append(firearm.Manufacturer).Append("', ");
            sb.Append("FirearmType = '").Append(firearm.FirearmType).Append("', ");
            sb.Append("AmmoType = '").Append(firearm.AmmoType).Append("', ");
            sb.Append("BarrelLength = ").Append(firearm.BarrelLength).Append(" ");
            sb.Append("WHERE ");
            sb.Append("ID = ").Append(firearm.ID);
            string sqlCommandString = sb.ToString();

            using (SqlConnection sqlConn = new SqlConnection(connString))
                using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
                {
                    try
                    {
                        sqlConn.Open();
                        sqlAdapter.UpdateCommand = new SqlCommand(sqlCommandString, sqlConn);
                        sqlAdapter.UpdateCommand.ExecuteNonQuery();
                    }
                    catch (SqlException sqlEx)
                    {
                        Console.WriteLine("SQL Exception: {0}", sqlEx.Message);
                        Console.WriteLine(sqlCommandString);
                    }
                }
        }
        private static void AddFirearm()
        {
            FirearmRepositorySQL firearmRepository = new FirearmRepositorySQL();
            Firearm firearm = new Firearm();

            firearm = ConsoleView.AddFirearm();
            using (firearmRepository)
            {
                firearmRepository.Insert(firearm);
            }

            ConsoleView.DisplayContinuePrompt();
        }
        private static void UpdateSkiRun()
        {
            FirearmRepositorySQL firearmRepository = new FirearmRepositorySQL();
            List <Firearm>       firearms          = firearmRepository.SelectAll();
            Firearm firearm = new Firearm();
            int     firearmID;

            using (firearmRepository)
            {
                firearms  = firearmRepository.SelectAll();
                firearmID = ConsoleView.GetFirearmID(firearms);
                firearm   = firearmRepository.SelectById(firearmID);
                firearm   = ConsoleView.UpdateFirearm(firearm);
                firearmRepository.Update(firearm);
            }
        }
        private static void DisplayFirearmDetail()
        {
            FirearmRepositorySQL firearmRepository = new FirearmRepositorySQL();
            List <Firearm>       firearms;
            Firearm firearm = new Firearm();
            int     firearmID;

            using (firearmRepository)
            {
                firearms  = firearmRepository.SelectAll();
                firearmID = ConsoleView.GetFirearmID(firearms);
                firearm   = firearmRepository.SelectById(firearmID);
            }

            ConsoleView.DisplayFirearm(firearm);
            ConsoleView.DisplayContinuePrompt();
        }
        /// <summary>
        /// method to display a firearm's info
        /// </summary>
        public static void DisplayFirearm(Firearm firearm)
        {
            DisplayReset();

            DisplayMessage("");
            Console.WriteLine(ConsoleUtil.Center("Firearm Detail", WINDOW_WIDTH));
            DisplayMessage("");

            DisplayMessage(String.Format("Firearm: {0}", firearm.Name));
            DisplayMessage("");

            DisplayMessage(String.Format("ID: {0}", firearm.ID.ToString()));
            DisplayMessage(String.Format("Manufacturer: {0}", firearm.Manufacturer.ToString()));
            DisplayMessage(String.Format("Type: {0}", firearm.FirearmType.ToString()));
            DisplayMessage(String.Format("Caliber/Guage: {0}", firearm.AmmoType.ToString()));

            DisplayMessage("");
        }
        private IEnumerable <Firearm> ReadAllFirearms()
        {
            IList <Firearm> firearms = new List <Firearm>();

            string connString       = GetConnectionString();
            string sqlCommandString = "SELECT * from Firearms";

            using (SqlConnection sqlConn = new SqlConnection(connString))
                using (SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConn))
                {
                    try
                    {
                        sqlConn.Open();
                        using (SqlDataReader reader = sqlCommand.ExecuteReader())
                        {
                            if (reader != null)
                            {
                                while (reader.Read())
                                {
                                    Firearm firearm = new Firearm();
                                    firearm.ID           = Convert.ToInt32(reader["ID"]);
                                    firearm.Name         = reader["Name"].ToString();
                                    firearm.Manufacturer = reader["Manufacturer"].ToString();
                                    firearm.FirearmType  = reader["FirearmType"].ToString();
                                    firearm.AmmoType     = reader["AmmoType"].ToString();
                                    firearm.BarrelLength = Convert.ToInt32(reader["BarrelLength"]);

                                    firearms.Add(firearm);
                                }
                            }
                        }
                    }
                    catch (SqlException sqlEx)
                    {
                        Console.WriteLine("SQL Exception: {0}", sqlEx.Message);
                        Console.WriteLine(sqlCommandString);
                    }
                }

            return(firearms);
        }
        private static void DeleteFirearm()
        {
            FirearmRepositorySQL firearmRepository = new FirearmRepositorySQL();
            List <Firearm>       firearms          = firearmRepository.SelectAll();
            Firearm firearm = new Firearm();
            int     firearmID;
            string  message;

            firearmID = ConsoleView.GetFirearmID(firearms);

            using (firearmRepository)
            {
                firearmRepository.Delete(firearmID);
            }

            ConsoleView.DisplayReset();

            message = String.Format("Firearm ID: {0} had been deleted.", firearmID);

            ConsoleView.DisplayMessage(message);
            ConsoleView.DisplayContinuePrompt();
        }
        /// <summary>
        /// method to add a firearm's info
        /// </summary>
        public static Firearm AddFirearm()
        {
            Firearm firearm = new Firearm();

            DisplayReset();

            DisplayMessage("");
            Console.WriteLine(ConsoleUtil.Center("Add A Firearm", WINDOW_WIDTH));
            DisplayMessage("");

            DisplayPromptMessage("Enter the firearm ID: ");
            firearm.ID = ConsoleUtil.ValidateIntegerResponse("Please enter the firearm ID: ", Console.ReadLine());
            Console.WriteLine("");

            DisplayPromptMessage("Enter the firearm name: ");
            firearm.Name = Console.ReadLine();
            Console.WriteLine("");

            DisplayPromptMessage("Enter the manufacturer: ");
            firearm.Manufacturer = Console.ReadLine();
            Console.WriteLine("");

            DisplayPromptMessage("Enter the firearm type: ");
            firearm.FirearmType = Console.ReadLine();
            Console.WriteLine("");

            DisplayPromptMessage("Enter the caliber/guage: ");
            firearm.AmmoType = Console.ReadLine();
            Console.WriteLine("");

            DisplayPromptMessage("Enter the barrel length: ");
            firearm.BarrelLength = ConsoleUtil.ValidateIntegerResponse("Please enter the barrel length: ", Console.ReadLine());
            Console.WriteLine("");

            return(firearm);
        }
        public static Firearm UpdateFirearm(Firearm firearm)
        {
            string userResponse = "";

            DisplayReset();

            DisplayMessage("");
            Console.WriteLine(ConsoleUtil.Center("Edit A Firearm", WINDOW_WIDTH));
            DisplayMessage("");

            DisplayMessage(String.Format("Current Name: {0}", firearm.Name));
            DisplayPromptMessage("Enter a new name or just press Enter to keep the current name: ");
            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                firearm.Name = userResponse;
            }

            DisplayMessage("");

            DisplayMessage(String.Format("Current Manufacturer: {0}", firearm.Manufacturer));
            DisplayPromptMessage("Enter a new manufacturer or just press Enter to keep the current manufacturer: ");
            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                firearm.Manufacturer = userResponse;
            }

            DisplayMessage("");

            DisplayMessage(String.Format("Current Type: {0}", firearm.FirearmType));
            DisplayPromptMessage("Enter a new type or just press Enter to keep the current type: ");
            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                firearm.FirearmType = userResponse;
            }

            DisplayMessage("");

            DisplayMessage(String.Format("Current Caliber/Guage: {0}", firearm.AmmoType));
            DisplayPromptMessage("Enter a new caliber/guage or just press Enter to keep the current caliber/guage: ");
            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                firearm.AmmoType = userResponse;
            }

            DisplayMessage("");

            DisplayMessage(String.Format("Current Barrel Length in cm: {0}", firearm.BarrelLength));
            DisplayPromptMessage("Enter a new barrel length or just press Enter to keep the current barrel length: ");
            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                firearm.BarrelLength = ConsoleUtil.ValidateIntegerResponse("Please enter the barrel length in cm.", userResponse);
            }

            DisplayMessage("");

            DisplayContinuePrompt();

            return(firearm);
        }