Пример #1
0
        //Mapping one Topic from DO to PO
        public static TopicPO MapDOtoPO(TopicDO from)
        {
            TopicPO to = new TopicPO();

            to.TopicID = from.TopicID;
            to.Topic   = from.Topic;

            //Returning Topic
            return(to);
        }
Пример #2
0
        /// <summary>
        /// Viewing Topics for DropDown List -- called in Controller RenderTopics()
        /// </summary>
        /// <returns></returns>
        public List <TopicDO> ViewTopics()
        {
            //Creating a new list to return
            List <TopicDO> allTopics = new List <TopicDO>();

            try
            {
                //Instantiating SqlConnection
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    //Creating a SqlCommand to use a stored procedure
                    SqlCommand cmd = new SqlCommand("DISPLAY_TOPICS", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    conn.Open();

                    //Filling table using adapter
                    DataTable topicsTable = new DataTable();
                    using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd))
                    {
                        dataAdapter.Fill(topicsTable);
                        dataAdapter.Dispose();
                    }

                    //Adding each topic into a list of topics
                    foreach (DataRow row in topicsTable.Rows)
                    {
                        TopicDO mappedTopic = MapAllTopics(row);
                        allTopics.Add(mappedTopic);
                    }
                }
            }
            catch (Exception ex)
            {
                //Error logging
                MunitionsErrorHandler("error", "MunitionsDAO", "ViewTopics", ex.Message, ex.StackTrace);
                throw ex;
            }
            //Returning all Topics
            return(allTopics);
        }
Пример #3
0
        /// <summary>
        /// Maps all topics by row -- called in ViewTopics()
        /// </summary>
        /// <param name="dataRow"></param>
        /// <returns></returns>
        public TopicDO MapAllTopics(DataRow dataRow)
        {
            //Instantiating new TopicDO to return topic
            TopicDO topic = new TopicDO();

            try
            {
                //checking data row for topicID of 0
                if ((Int64)dataRow["TopicID"] != 0)
                {
                    topic.TopicID = (Int64)dataRow["TopicID"];
                }
                topic.Topic = dataRow["Topic"].ToString();
            }
            catch (Exception ex)
            {
                //Error logging
                MunitionsErrorHandler("error", "MunitionsDAO", "MapAllTopics", ex.Message, ex.StackTrace);
                throw ex;
            }
            //Returning topic
            return(topic);
        }