Exemple #1
0
        public Boolean updateHighlightNoImg(News_highlights a) // Update.
        {
            SqlConnection conn         = new SqlConnection();
            Boolean       rowsAffected = false;

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText =
                    "Update [News_highlights] SET title=@title, body=@body, news_text=@text, type=@type WHERE highlight_id = @id";
                comm.Parameters.AddWithValue("@title", a.title);
                comm.Parameters.AddWithValue("@body", a.body);
                comm.Parameters.AddWithValue("@text", a.news_text);
                //comm.Parameters.AddWithValue("@img_path", a.img_path);
                comm.Parameters.AddWithValue("@type", a.type);
                comm.Parameters.AddWithValue("@id", a.highlight_id);
                rowsAffected = true;
                comm.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(rowsAffected);
        }
Exemple #2
0
        public int createNewsHighlight(News_highlights a) // Insert.
        {
            SqlConnection conn     = null;
            int           toReturn = 0;

            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "insert into [News_highlights] (date_posted, title, body, news_text, status, user_id, img_path, type) OUTPUT INSERTED.highlight_id VALUES"
                                   + "(@date, @title, @body, @text, @status, @uid, @img_path, @type)";
                comm.Parameters.AddWithValue("@date", a.entry_time);
                comm.Parameters.AddWithValue("@title", a.title);
                comm.Parameters.AddWithValue("@body", a.body);
                comm.Parameters.AddWithValue("@text", a.news_text);
                comm.Parameters.AddWithValue("@status", a.status);
                comm.Parameters.AddWithValue("@uid", a.user.getUserID());
                comm.Parameters.AddWithValue("@img_path", a.img_path);
                comm.Parameters.AddWithValue("@type", a.type);
                int v = (Int32)comm.ExecuteScalar();
                toReturn = getHighlightIdLatest();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            User    currentUser  = (User)Session["currentUser"];
            Boolean authenticate = authenticateAccess(currentUser);

            if (Request.QueryString["id"] != null)
            {
                if (!authenticate)
                {
                    Response.Redirect("errorPage.aspx");
                }
                else
                {
                    //TestimonialDAO tdao = new TestimonialDAO();
                    string             id     = Request.QueryString["id"];
                    int                id_num = Convert.ToInt32(id);
                    News_highlightsDAO adao   = new News_highlightsDAO();
                    adao.deactivateNewsHighlight(id_num);
                    News_highlights obj = adao.getHighlightById(id_num);
                    if (File.Exists(obj.img_path))
                    {
                        File.Delete(obj.img_path);
                    }
                    //set audit
                    setAudit(currentUser, "news", "delete", id, "deleted news title: " + obj.title);

                    Response.Redirect("manageNews.aspx");
                }
            }
            else
            {
                Response.Redirect("errorPage.aspx");
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            News_highlights edited = new News_highlights();
            string          id     = Request.QueryString["id"];

            if (id == null || id.Equals(""))
            {
                Response.Redirect("errorPage.aspx");
            }
            int id_num = Convert.ToInt32(id);

            edited.highlight_id = id_num;
            edited.title        = txtTitle.Text;
            edited.body         = txtDesc.Text;
            edited.news_text    = descriptionModuleInput.Text;
            edited.type         = ddlType.SelectedValue;
            if (FileUpload1.HasFile)
            {
                string fileName      = FileUpload1.FileName;
                string filepath      = "img/highlights" + "/";
                string FileExtension = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();
                if (FileExtension.Equals("jpeg") || FileExtension.Equals("png") || FileExtension.Equals("jpg"))
                {
                    FileUpload1.PostedFile
                    .SaveAs(Server.MapPath(filepath) + fileName);
                    string totalpath1 = Server.MapPath(filepath) + fileName;
                    edited.img_path = totalpath1;
                    News_highlightsDAO ndao = new News_highlightsDAO();
                    Boolean            done = ndao.updateHighlight(edited);
                    if (done)
                    {
                        //set audit
                        User currentUser = (User)Session["currentUser"];
                        setAudit(currentUser, "news", "update", id, "updated news title: " + txtTitle.Text);

                        Response.Redirect("manageNews.aspx");
                    }
                }
            }
            else
            {
                News_highlightsDAO ndao = new News_highlightsDAO();
                Boolean            done = ndao.updateHighlightNoImg(edited);
                if (done)
                {
                    //set audit
                    User currentUser = (User)Session["currentUser"];
                    setAudit(currentUser, "news", "update", id, "updated news title: " + txtTitle.Text);

                    Response.Redirect("manageNews.aspx");
                }
            }
        }
        //protected int id_num;
        protected void Page_Load(object sender, EventArgs e)
        {
            User currentUser = (User)Session["currentUser"];

            if (currentUser == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                Boolean superuser       = false;
                Boolean content_creator = false;
                foreach (string s in currentUser.getRoles())
                {
                    if (s.Equals("superuser"))
                    {
                        superuser = true;
                    }
                    else if (s.Equals("content creator"))
                    {
                        content_creator = true;
                    }
                }
                if (superuser || content_creator)
                {
                    if (!IsPostBack)
                    {
                        string id = Request.QueryString["id"];
                        if (id == null || id.Equals(""))
                        {
                            Response.Redirect("errorPage.aspx");
                        }
                        int id_num = Convert.ToInt32(id);
                        News_highlightsDAO ndao = new News_highlightsDAO();
                        News_highlights    news = ndao.getHighlightById(id_num);
                        ddlType.SelectedValue       = news.type;
                        txtTitle.Text               = news.title;
                        txtDesc.Text                = news.body;
                        descriptionModuleInput.Text = news.news_text;
                    }
                }
                else
                {
                    Response.Redirect("errorPage.aspx");
                }
            }
        }
Exemple #6
0
        public News_highlights getHighlightById(int id)
        {
            SqlConnection   conn = new SqlConnection();
            News_highlights a    = new News_highlights();
            UserDAO         udao = new UserDAO();

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from [News_highlights] where highlight_id = @aid";
                comm.Parameters.AddWithValue("@aid", id);
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    //News_highlights a = new News_highlights();
                    string userid   = (string)dr["user_id"];
                    User   user_now = udao.getUserByID(userid);
                    a.user         = user_now;
                    a.entry_time   = ((DateTime)dr["date_posted"]);
                    a.title        = ((string)dr["title"]);
                    a.body         = ((string)dr["body"]);
                    a.news_text    = ((string)dr["news_text"]);
                    a.highlight_id = ((int)dr["highlight_id"]);
                    string status = (string)dr["status"];
                    a.img_path = ((string)dr["img_path"]);
                    a.type     = ((string)dr["type"]);
                    //toReturn.Add(a);
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(a);
        }
Exemple #7
0
        public ArrayList getNewsHighlights()
        {
            SqlConnection conn     = new SqlConnection();
            ArrayList     toReturn = new ArrayList();
            UserDAO       udao     = new UserDAO();

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from [News_highlights] where status = 'Active' order by date_posted desc";
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    News_highlights a        = new News_highlights();
                    string          userid   = (string)dr["user_id"];
                    User            user_now = udao.getUserByID(userid);
                    a.user         = user_now;
                    a.entry_time   = ((DateTime)dr["date_posted"]);
                    a.title        = ((string)dr["title"]);
                    a.body         = ((string)dr["body"]);
                    a.news_text    = ((string)dr["news_text"]);
                    a.highlight_id = ((int)dr["highlight_id"]);
                    string status = (string)dr["status"];
                    a.img_path = ((string)dr["img_path"]);
                    a.type     = ((string)dr["type"]);
                    toReturn.Add(a);
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string title = txtTitle.Text;
            string desc  = txtDesc.Text;
            string type  = ddlType.SelectedValue;
            string total = descriptionModuleInput.Text;

            if (FileUpload1.HasFile)
            {
                string fileName      = FileUpload1.FileName;
                string filepath      = "img/highlights" + "/";
                string FileExtension = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();
                if (FileExtension.Equals("jpeg") || FileExtension.Equals("png") || FileExtension.Equals("jpg"))
                {
                    FileUpload1.PostedFile
                    .SaveAs(Server.MapPath(filepath) + fileName);
                    string          totalpath1 = Server.MapPath(filepath) + fileName;
                    News_highlights n          = new News_highlights();
                    n.title      = title;
                    n.status     = "Active";
                    n.entry_time = DateTime.Now;
                    n.type       = type;
                    n.body       = desc;
                    n.news_text  = total;
                    n.img_path   = totalpath1;
                    n.user       = (User)Session["currentUser"];
                    n.type       = type;
                    News_highlightsDAO ndao = new News_highlightsDAO();
                    int id = ndao.createNewsHighlight(n);

                    //set audit
                    User currentUser = (User)Session["currentUser"];
                    setAudit(currentUser, "news", "create", id.ToString(), "created news title: " + title);

                    Response.Redirect("home.aspx");
                }
            }
        }