public NewsBE getNews(int code) { NewsBE news = new NewsBE(); SqlConnection c = new SqlConnection(connection); c.Open(); SqlCommand com = new SqlCommand("SELECT * FROM news WHERE code='" + code + "'", c); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { news.Code = Int32.Parse(dr["code"].ToString()); news.Title = dr["title"].ToString(); news.Content = dr["content"].ToString(); news.PublicationDate = DateTime.ParseExact(dr["public_date"].ToString(), "dd/MM/yyyy", null); news.Author = new UserBE(); news.Author.Nickname = dr["creator"].ToString(); } c.Close(); return news; }
protected void update_News(object sender, EventArgs e) { NewsBE news = new NewsBE(); news.Title = TitleTB.Text; news.Code = Int32.Parse(Request.QueryString["code"]); news.Content = ContentTB.Text; //Update the UserBE credits and also the Sessión value. news.update(); Response.Redirect("NewsAdmin.aspx"); }
protected void create_News(object sender, EventArgs e) { NewsBE news = new NewsBE(); news.Title = TitleTB.Text; if (Request.QueryString["code"]!=null) news.Code = Int32.Parse(Request.QueryString["code"]); news.Content = ContentTB.Text; news.PublicationDate = DateTime.Now; UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE author = new UserBE(user1.getUserByNick()); news.Author = author; news.create(); Response.Redirect("NewsAdmin.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //We need the title and the code. Otherwise the user must be playing with the URL. if (Request.QueryString["code"] != null) { NewsBE en = new NewsBE(); en = en.getByCode(Int32.Parse(Request.QueryString["code"])); TitleTB.Text = en.Title; ContentTB.Text = en.Content; } HttpCookie userCookie = Request.Cookies["UserNickname"]; if (userCookie != null) SiteMaster.loadCookie(userCookie); } }
public void update(NewsBE news) { SqlConnection c = new SqlConnection(connection); c.Open(); SqlCommand com = new SqlCommand("UPDATE news " + "SET title='" + news.Title + "', content='" + news.Content + "'" + " WHERE code='" + news.Code + "'", c); com.ExecuteNonQuery(); c.Close(); }
/* ****************************************************************** */ /* Methods */ /* ****************************************************************** */ public string insertNews(NewsBE news) { string result = "The news item has been created!"; SqlConnection c = new SqlConnection(connection); c.Open(); SqlCommand com = new SqlCommand("INSERT INTO news (code, title, content, public_date, creator)" + " VALUES ('" + news.Code + "','" + news.Title + "','" + news.Content + "','" + news.PublicationDate.ToString("dd/MM/yyyy") + "','" + news.Author.Email + "')", c); com.ExecuteNonQuery(); c.Close(); return result; }