// Make appropriate comment
        public SupportLinksDO MapReaderToSingle(SqlDataReader reader)
        {
            SupportLinksDO result = new SupportLinksDO();

            // Make appropriate comment - Overview this section here
            if (reader["SupportId"] != DBNull.Value)
            {
                result.SupportId = (long)reader["SupportId"];
            }
            if (reader["Name"] != DBNull.Value)
            {
                result.Name = (string)reader["Name"];
            }
            if (reader["Address"] != DBNull.Value)
            {
                result.Address = (string)reader["Address"];
            }
            if (reader["Phone"] != DBNull.Value)
            {
                result.Phone = (string)reader["Phone"];
            }
            if (reader["Url"] != DBNull.Value)
            {
                result.Url = (string)reader["Url"];
            }
            if (reader["UserId"] != DBNull.Value)
            {
                result.UserId = (long)reader["UserId"];
            }
            return(result);
        }
Пример #2
0
        public ActionResult CreateSupportLinks(SupportLinks form)
        {
            ActionResult response;

            try
            {
                // checking to see if valid
                if (ModelState.IsValid)
                {
                    // checking for http
                    if (!form.Url.StartsWith("https://"))
                    {
                        // adding http
                        form.Url = "https://" + form.Url;
                    }

                    // creating dataobject
                    SupportLinksDO dataObject = new SupportLinksDO()
                    {
                        //paramaters for support links
                        SupportId = form.SupportId,
                        Name      = form.Name,
                        Address   = form.Address,
                        Phone     = form.Phone,
                        Url       = form.Url,
                        UserId    = (long)Session["UserId"]
                    };
                    // display param info
                    SupportLinksDataAccess.CreateSupportLinks(dataObject);


                    TempData["SupportId"] = dataObject.SupportId;
                    response = RedirectToAction("AllSupportLinks", "SupportLinks");
                }
                else
                {
                    response = View(form);
                }
            }
            catch (SqlException Sqlex)
            {
                //Log exception for sql
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex);
                response            = View(form);
                TempData["Message"] = "Connection Error";
            }
            catch (Exception ex)
            {
                // log exception for other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                response            = View(form);
                TempData["Message"] = "Error Try Again";
            }
            return(response);
        }
Пример #3
0
        /// <summary>
        ///  mapping the PO to DO
        /// </summary>
        /// <param name="from"></param>
        /// <returns> send it out</returns>
        public SupportLinksDO MapPoToDo(SupportLinks from)
        {
            SupportLinksDO to = new SupportLinksDO();

            to.SupportId = from.SupportId;
            to.Name      = from.Name;
            to.Address   = from.Address;
            to.Phone     = from.Phone;
            to.Url       = from.Url;
            to.UserId    = from.UserId;

            return(to);
        }
Пример #4
0
        /// <summary>
        /// DO to PO
        /// </summary>
        /// <param name="from"></param>
        /// <returns> sends information out</returns>
        public SupportLinks MapDoToPo(SupportLinksDO from)
        {
            SupportLinks to = new SupportLinks();

            to.SupportId = from.SupportId;
            to.Name      = from.Name;
            to.Address   = from.Address;
            to.Phone     = from.Phone;
            to.Url       = from.Url;
            to.UserId    = from.UserId;

            return(to);
        }
Пример #5
0
        public SupportLinksDO ViewSupportLinksById(long supportId)
        {
            // instatiate support
            SupportLinksDO support = new SupportLinksDO();

            try
            {
                // sql connection
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                    using (SqlCommand command = new SqlCommand("View_Support_Links_By_Id", connection))
                    {
                        // sql commands
                        command.CommandType    = CommandType.StoredProcedure;
                        command.CommandTimeout = 60;

                        // paramaters
                        command.Parameters.AddWithValue("@SupportId", supportId);

                        // open connection
                        connection.Open();

                        // mapping from sql
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                //info from sql
                                support.SupportId = reader["SupportId"] != DBNull.Value ? (long)reader["SupportId"] : 0;
                                support.Name      = reader["Name"] != DBNull.Value ? (string)reader["Name"] : null;
                                support.Address   = reader["Address"] != DBNull.Value ? (string)reader["Address"] : null;
                                support.Phone     = reader["Phone"] != DBNull.Value ? (string)reader["Phone"] : null;
                                support.Url       = reader["Url"] != DBNull.Value ? (string)reader["Url"] : null;
                                support.UserId    = reader["UserId"] != DBNull.Value ? (long)reader["UserId"] : 0;
                            }
                        }
                    }
            }
            catch (SqlException Sqlex)
            {
                //Log exception for sql
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex);
            }
            catch (Exception ex)
            {
                // log other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
            }
            return(support);
        }
Пример #6
0
        public List <SupportLinksDO> ViewAllSupportLinks()
        {
            // instatiates support links
            List <SupportLinksDO> displaySupportLinks = new List <SupportLinksDO>();

            try
            {
                // sql connection
                using (SqlConnection connectionStrongerTogether = new SqlConnection(ConnectionString))
                    using (SqlCommand viewSupportLinks = new SqlCommand("View_All_Support_Links", connectionStrongerTogether))
                    {
                        // stored procedures
                        viewSupportLinks.CommandType = CommandType.StoredProcedure;
                        connectionStrongerTogether.Open();

                        // view and execute from sql
                        using (SqlDataReader sqlDataReader = viewSupportLinks.ExecuteReader())
                        {
                            while (sqlDataReader.Read())
                            {
                                // mapping the links
                                SupportLinksDO supportLinks = mapper.MapReaderToSingle(sqlDataReader);
                                displaySupportLinks.Add(supportLinks);
                            }
                        }

                        // close connection
                        connectionStrongerTogether.Close();
                    }
            }
            catch (SqlException sqlex)
            {
                // log sql exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
            }
            catch (Exception ex)
            {
                // log other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
            }
            return(displaySupportLinks);
        }
Пример #7
0
        public ActionResult DeleteSupportLinks(long supportId)
        {
            ActionResult response;

            // creating variables and mapping
            SupportLinksDO supportLinks       = SupportLinksDataAccess.ViewSupportLinksById(supportId);
            SupportLinks   deleteSupportLinks = mapper.MapDoToPo(supportLinks);
            long           supportID          = deleteSupportLinks.SupportId;


            try
            {
                //check to see if id is valid
                if (supportId > 0)
                {
                    // if valid
                    SupportLinksDataAccess.DeleteSupportLinks(supportId);
                    response = RedirectToAction("AllSupportLinks", "SupportLinks");
                }
                else
                {
                    // if not valid
                    response = RedirectToAction("AllSupportLinks", "SupportLinks");
                }
            }
            catch (SqlException Sqlex)
            {
                //Log exception for sql
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex);
                response            = View(supportLinks);
                TempData["Message"] = "Connection Error";
            }
            catch (Exception ex)
            {
                // log exception for other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                response            = View(supportLinks);
                TempData["Message"] = "Error Try Again";
            }
            return(response);
        }
Пример #8
0
        public ActionResult UpdateSupportLinks(SupportLinks form)
        {
            ActionResult response;

            try
            {
                // checking to see if valid
                if (ModelState.IsValid)
                {
                    // mapping
                    SupportLinksDO supportLinksDO = mapper.MapPoToDo(form);
                    SupportLinksDataAccess.UpdateSupportLinks(supportLinksDO);

                    // redirect
                    response = RedirectToAction("AllSupportLinks", "SupportLinks");
                }
                else
                {
                    // if not valid
                    response = View(form);
                }
            }
            catch (SqlException Sqlex)
            {
                //Log exception for sql
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex);
                response            = View(form);
                TempData["Message"] = "Connection Error";
            }
            catch (Exception ex)
            {
                // log exception for other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                response            = View(form);
                TempData["Message"] = "Error Try Again";
            }
            return(response);
        }
Пример #9
0
        public void UpdateSupportLinks(SupportLinksDO supportLinks)
        {
            try
            {
                // sql connection
                using (SqlConnection connectionStrongerTogether = new SqlConnection(ConnectionString))
                    using (SqlCommand updateSupportLinks = new SqlCommand("Update_Support_Links", connectionStrongerTogether))
                    {
                        // stored procedures
                        updateSupportLinks.CommandType    = CommandType.StoredProcedure;
                        updateSupportLinks.CommandTimeout = 60;

                        // stroed paramaters
                        updateSupportLinks.Parameters.AddWithValue("@SupportId", supportLinks.SupportId);
                        updateSupportLinks.Parameters.AddWithValue("@Name", supportLinks.Name);
                        updateSupportLinks.Parameters.AddWithValue("@Address", supportLinks.Address);
                        updateSupportLinks.Parameters.AddWithValue("@Phone", supportLinks.Phone);
                        updateSupportLinks.Parameters.AddWithValue("@Url", supportLinks.Url);
                        updateSupportLinks.Parameters.AddWithValue("@UserId", supportLinks.UserId);

                        // executes
                        connectionStrongerTogether.Open();
                        updateSupportLinks.ExecuteNonQuery();
                        connectionStrongerTogether.Close();
                    }
            }
            catch (SqlException Sqlex)
            {
                //Log exception sql
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex);
            }
            catch (Exception ex)
            {
                // log other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
            }
        }
Пример #10
0
        public void CreateSupportLinks(SupportLinksDO createSupportLinks)
        {
            try
            {
                // calling on sql
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                    using (SqlCommand command = new SqlCommand("Create_Support_Links", connection))
                    {
                        // calls on stored procedures
                        command.CommandType    = CommandType.StoredProcedure;
                        command.CommandTimeout = 60;

                        // params from sql
                        command.Parameters.AddWithValue("@Name", createSupportLinks.Name);
                        command.Parameters.AddWithValue("@Address", createSupportLinks.Address);
                        command.Parameters.AddWithValue("@Phone", createSupportLinks.Phone);
                        command.Parameters.AddWithValue("@Url", createSupportLinks.Url);
                        command.Parameters.AddWithValue("@UserId", createSupportLinks.UserId);

                        // executes sql
                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
            }
            catch (SqlException Sqlex)
            {
                //Log exception sql
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Sqlex);
            }
            catch (Exception ex)
            {
                // log other exceptions
                logger.ErrorLogger(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
            }
        }