public Inbox getInbox(int id) { Inbox inbox = new Inbox(); String sql = "Select *From Inbox where id_user = '******'"; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); SqlDataReader reader = Comando.ExecuteReader(); while (reader.Read()) { inbox.id = reader.GetInt32(0); inbox.id_user= reader.GetInt32(1); inbox.msg_in = reader.GetInt32(2); inbox.msg_in = reader.GetInt32(3); } } return inbox; }
public ActionResult EnviarMP() { Session["UserIDG"] = Session["UserIDG"]; Session["UserID"] = Session["UserID"]; Session["User"] = Session["User"]; ViewBag.Message = "Mensaje Privado"; User user = new User(); Inbox inbox = new Inbox(); int retorno = 0; string message = (string)Request["Mensaje"]; string title = (string)Request["title"]; string destiny = (string)Request["Destinatario"]; int origen = (int)Session["UserID"]; if (!user.Checkuser(destiny)) { MessageBox.Show("No Existe Usuario Destino", "Invalido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return Redirect("MP"); } user = user.getUser(destiny); inbox = inbox.getInbox(user.id); DateTime thisDay = DateTime.Now; string date = thisDay.ToString(); String sql = "Insert into mp (id_userfrom,id_inbox,title,check_read,messages,date_send)" + "values ('{0}','{1}','{2}','{3}','{4}','{5}')"; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql, origen, inbox.id, title, 0, message, date), connection); retorno = Comando.ExecuteNonQuery(); connection.Close(); } if (retorno > 0) { MessageBox.Show("Mensaje Enviado Con Exito!!", "Enviado", MessageBoxButtons.OK, MessageBoxIcon.Information); return Redirect("UserIn"); } else { MessageBox.Show("No se pudo enviar el Mensaje", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return Redirect("MP"); ; }