Example #1
0
        /// <summary>
        /// Insert New Message.
        /// </summary>
        /// <param name="messageDAL"></param>
        private static void InsertNewMessage(QuoteBoxDALC QuoteBoxDALC)
        {
            Console.WriteLine("Enter new message text: ");
            string newMessageTxt = Console.ReadLine() ?? "";

            // Now pass to data access lib.
            Console.WriteLine("Inserting new message...\n");
            QuoteBoxDALC.CreateMessage(newMessageTxt);
        }
Example #2
0
        /// <summary>
        /// Show All Messages.
        /// </summary>
        /// <param name="messageDAL"></param>
        private static void ShowAllMessages(QuoteBoxDALC QuoteBoxDALC)
        {
            // Get the collection of messages.
            List <string> messageList = QuoteBoxDALC.ReadAllMessages();

            // Print out the messages.
            Console.WriteLine("\n------------------------------------------------");

            foreach (string message in messageList)
            {
                Console.WriteLine($"--> \"{message}\"");
            }

            Console.WriteLine();
        }
Example #3
0
        /// <summary>
        /// Look Up Message.
        /// </summary>
        /// <param name="messageDAL"></param>
        private static void LookUpMessage(QuoteBoxDALC QuoteBoxDALC)
        {
            // Get Id of message to look up.
            Console.WriteLine("Enter ID of message to look up: ");
            int messageId = int.Parse(Console.ReadLine() ?? "0");

            if (messageId > 0)
            {
                Console.WriteLine("Looking up message...");
                Console.WriteLine("\n------------------------------------------------");
                Console.WriteLine($"--> \"{QuoteBoxDALC.ReadMessage(messageId).TrimEnd()}\".");
            }
            else
            {
                Console.WriteLine("Error, could not look up message!");
            }
        }
Example #4
0
        /// <summary>
        /// Update Message.
        /// </summary>
        /// <param name="messageDAL"></param>
        private static void UpdateMessage(QuoteBoxDALC QuoteBoxDALC)
        {
            // Get user data.
            Console.WriteLine("Enter message ID: ");
            int messageId = int.Parse(Console.ReadLine() ?? "0");

            Console.WriteLine("Enter new message: ");
            string newMessageTxt = Console.ReadLine();

            // Now pass to data access lib.
            if (messageId > 0)
            {
                Console.WriteLine("Updating message...\n");
                QuoteBoxDALC.UpdateMessage(messageId, newMessageTxt);
            }
            else
            {
                Console.WriteLine("Error, could not update message!");
            }
        }
Example #5
0
        private static void LookUpQuote(QuoteBoxDALC QuoteBoxDALC)
        {
            // Get Id of message to look up.
            Console.WriteLine("Enter ID of quote to look up: ");
            int messageId = int.Parse(Console.ReadLine() ?? "1");

            if (messageId > 0)
            {
                Console.WriteLine("Looking up quote...\n");
                DataTable dataTable = QuoteBoxDALC.ReadQuote(messageId);

                if (dataTable.Rows.Count > 0)
                {
                    DataRow dr = dataTable.Rows[0];

                    Console.WriteLine("\n--------------------------------------------------------------------");
                    Console.WriteLine("\nLook Up Quote:");
                    Console.WriteLine("\n--------------------------------------------------------------------");
                    Console.WriteLine($"QuoteId: {dr["QuoteId"].ToString()}");
                    Console.WriteLine($"AuthorId: {dr["AuthorId"].ToString()}");
                    Console.WriteLine($"FirstName: {dr["FirstName"].ToString()}");
                    Console.WriteLine($"MiddleName: {dr["MiddleName"].ToString()}");
                    Console.WriteLine($"LastName: {dr["LastName"].ToString()}");
                    Console.WriteLine($"AdditionalTxt: {dr["AdditionalTxt"].ToString()}");
                    Console.WriteLine($"AuthorCreatedDtm: {dr["AuthorCreatedDtm"].ToString()}");
                    Console.WriteLine($"QuoteTxt: {dr["QuoteTxt"].ToString()}");
                    Console.WriteLine($"QuoteCreatedDtm: {dr["QuoteCreatedDtm"].ToString()}");
                    Console.WriteLine("\n--------------------------------------------------------------------\n");
                }
                else
                {
                    Console.WriteLine("Error: No rows to process!");
                }
            }
            else
            {
                Console.WriteLine("Error, could not look up message!");
            }
        }
Example #6
0
        /// <summary>
        /// Delete Message.
        /// </summary>
        /// <param name="messageDAL"></param>
        private static void DeleteMessage(QuoteBoxDALC QuoteBoxDALC)
        {
            // Get Id of message to delete.
            Console.WriteLine("Enter ID of Message to delete: ");
            int messageId = int.Parse(Console.ReadLine() ?? "0");

            // Just in case you have a referential integrity violation!
            try
            {
                if (messageId > 0)
                {
                    Console.WriteLine("Deleting message...\n");
                    QuoteBoxDALC.DeleteMessage(messageId);
                }
                else
                {
                    Console.WriteLine("Error, could not update message!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        //Methods.
        List <QuoteRecord> IQuoteBoxService.GetQuote(int id)
        {
            // Create list.
            List <QuoteRecord> quoteRecordList = new List <QuoteRecord> {
            };

            if (id > 0)
            {
                // Get connection string from App.config.
                //_connectionString = ConfigurationManager.ConnectionStrings["MessageBoxSqlProvider"].ConnectionString;

                // Create our MessageBoxDAL obeject.
                QuoteBoxDALC quoteBoxDALC = new QuoteBoxDALC();
                try
                {
                    quoteBoxDALC.OpenConnection(_connectionString);

                    //Logfile.WriteLine("Looking up quote...\n");
                    DataTable dataTable = quoteBoxDALC.ReadQuote(id);

                    if (dataTable.Rows.Count > 0)
                    {
                        DataRow     dr          = dataTable.Rows[0];
                        QuoteRecord quoteRecord = new QuoteRecord
                        {
                            QuoteId          = (int)dr["QuoteId"],
                            AuthorId         = (int)dr["AuthorId"],
                            FirstName        = dr["FirstName"].ToString(),
                            MiddleName       = dr["MiddleName"].ToString(),
                            LastName         = dr["LastName"].ToString(),
                            AdditionalTxt    = dr["AdditionalTxt"].ToString(),
                            AuthorCreatedDtm = (DateTime)dr["AuthorCreatedDtm"],
                            QuoteTxt         = dr["QuoteTxt"].ToString(),
                            QuoteCreatedDtm  = (DateTime)dr["QuoteCreatedDtm"]
                        };

                        quoteRecordList.Add(quoteRecord);
                        return(quoteRecordList);
                    }
                    else
                    {
                        //Logfile.WriteLine("Error: No rows to process!");
                        return(quoteRecordList);
                    }
                }
                catch (Exception ex)
                {
                    // Logfile: Exception.
                    throw new Exception("Error: GetQuote encountered an unexpected exception!", ex);
                }
                finally
                {
                    quoteBoxDALC.CloseConnection();
                }
            }
            else
            {
                //Logfile.WriteLine("Error: No rows to process!");
                return(quoteRecordList);
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** QuoteBox Test Console *****\n");

            // Get connection string from App.config.
            string connectionString =
                ConfigurationManager.ConnectionStrings["QuoteBoxSqlProvider"].ConnectionString;

            bool   userDone    = false;
            string userCommand = "";

            // Create our QuoteBoxDAL obeject.
            QuoteBoxDALC quoteBoxDALC = new QuoteBoxDALC();

            quoteBoxDALC.OpenConnection(connectionString);

            // Keep asking for input until the user presses the [Q] key.
            try
            {
                ShowInstructions();
                do
                {
                    Console.WriteLine("\nPlease enter your command: ");
                    userCommand = Console.ReadLine();
                    Console.WriteLine();

                    switch (userCommand?.ToUpper() ?? "")
                    {
                    case "I":
                        InsertNewMessage(quoteBoxDALC);
                        break;

                    case "U":
                        UpdateMessage(quoteBoxDALC);
                        break;

                    case "D":
                        DeleteMessage(quoteBoxDALC);
                        break;

                    case "L":
                        ShowAllMessages(quoteBoxDALC);
                        break;

                    case "S":
                        ShowInstructions();
                        break;

                    case "M":
                        LookUpMessage(quoteBoxDALC);
                        break;

                    case "Q":
                        LookUpQuote(quoteBoxDALC);
                        break;

                    case "X":
                        userDone = true;
                        break;

                    default:
                        Console.WriteLine("Bad data! Try again.");
                        break;
                    }
                } while (!userDone);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                quoteBoxDALC.CloseConnection();
            }

            Console.ReadLine();
        }