public ThreadDO ViewThreadByID(int id)
        {
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;
            SqlDataReader reader          = null;
            ThreadDO      threadDO        = new ThreadDO();

            try
            {
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("THREAD_VIEW_BY_THREAD_ID", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;
                storedProcedure.Parameters.AddWithValue("@ThreadID", id);

                connectionToSql.Open();
                reader = storedProcedure.ExecuteReader();

                while (reader.Read())
                {
                    threadDO.ThreadId    = (int)reader["ThreadID"];
                    threadDO.Title       = reader["Title"] as string;
                    threadDO.Information = reader["Information"] as string;
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            return(threadDO);
        }
        public ActionResult AddThread(ThreadPO form)
        {
            ActionResult response = null;

            if (ModelState.IsValid)
            {
                try
                {
                    //maps and adds the user inputted thread information to the database
                    ThreadDO dataObject = ThreadMapper.ThreadPOToDO(form);
                    _threadDataAccess.AddThread(dataObject);
                    //sends user back to the list of threads page
                    response = RedirectToAction("Index", "Thread");
                }
                catch (Exception ex)
                {
                    Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                }
            }
            else
            {
                response = View(form);
            }
            return(response);
        }
Beispiel #3
0
        public void AddThread(ThreadDO form)
        {
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;

            try
            {
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("THREAD_ADD", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;

                storedProcedure.Parameters.AddWithValue("@Title", form.Title);
                storedProcedure.Parameters.AddWithValue("@Information", form.Information);

                connectionToSql.Open();
                storedProcedure.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
        }
        public static ThreadDO ThreadPOToDO(ThreadPO from)
        {
            ThreadDO to = new ThreadDO();

            to.ThreadId    = from.ThreadId;
            to.Title       = from.Title;
            to.Information = from.Information;
            return(to);
        }
        public ActionResult UpdateThread(int threadId)
        {
            ActionResult response = null;

            try
            {
                //shows the update form for the thread that was clicked
                ThreadDO dataObject    = _threadDataAccess.ViewThreadByID(threadId);
                ThreadPO displayObject = ThreadMapper.ThreadDOToPO(dataObject);
                response = View(displayObject);
            }
            catch (Exception ex)
            {
                Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
            }
            return(response);
        }
Beispiel #6
0
        public List <ThreadDO> ViewAllThreads()
        {
            SqlConnection   connectionToSql = null;
            SqlCommand      storedProcedure = null;
            SqlDataReader   reader          = null;
            List <ThreadDO> threadList      = new List <ThreadDO>();

            try
            {
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("THREAD_VIEW_ALL", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;

                connectionToSql.Open();
                reader = storedProcedure.ExecuteReader();

                while (reader.Read())
                {
                    ThreadDO threadDO = new ThreadDO();

                    threadDO.ThreadId    = (int)reader["ThreadID"];
                    threadDO.Title       = reader["Title"] as string;
                    threadDO.Information = reader["Information"] as string;
                    threadList.Add(threadDO);
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
            return(threadList);
        }
        public ActionResult UpdateThread(ThreadPO form)
        {
            ActionResult response = null;

            if (ModelState.IsValid)
            {
                try
                {
                    //updates the thread with user inputted information
                    ThreadDO dataObject = ThreadMapper.ThreadPOToDO(form);
                    _threadDataAccess.UpdateThread(dataObject);
                    response = RedirectToAction("Index", "Thread");
                }
                catch (Exception ex)
                {
                    Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                }
            }
            else
            {
                response = View(form);
            }
            return(response);
        }