public MP getMPByID(int id) { MP mp = new MP(); String sql = "Select *From MP where id_message = '" + id + "'"; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); SqlDataReader reader = Comando.ExecuteReader(); while (reader.Read()) { mp.id = reader.GetInt32(0); mp.id_from = reader.GetInt32(1); mp.id_inbox = reader.GetInt32(2); mp.title = reader.GetString(3); mp.check = reader.GetInt32(4); mp.msg = reader.GetString(5); mp.date_send = reader.GetString(6); } } return(mp); }
public List<MP> getMyMPs(int id) { List<MP> mps = new List<MP>(); String sql = "Select *From MP where id_inbox = '" + id + "'"; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); SqlDataReader reader = Comando.ExecuteReader(); while (reader.Read()) { MP mp = new MP(); mp.id = reader.GetInt32(0); mp.id_from = reader.GetInt32(1); mp.id_inbox = reader.GetInt32(2); mp.title = reader.GetString(3); mp.check = reader.GetInt32(4); mp.msg = reader.GetString(5); mp.date_send = reader.GetString(6); mps.Add(mp); } } return mps; }
public ActionResult VerMP(int id) { ViewBag.Message = "Inbox"; Session["UserIDG"] = Session["UserIDG"]; Session["UserID"] = Session["UserID"]; Session["User"] = Session["User"]; MP mp = new MP(); mp = mp.getMPByID(id); User user = new User(); user = user.getUserID(mp.id_from); List<string> items = new List<string>(); items.Add(mp.title); items.Add(mp.date_send); items.Add(mp.msg); items.Add(user.name); ViewBag.Items = items; if (mp.check.Equals(1)) { return View(); } String sql = "Update MP set check_read = '1' where id_message = '" + id + "'"; int retorno = 0; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); retorno = Comando.ExecuteNonQuery(); connection.Close(); } return View(); }