public static Post Parse(MySqlDataReader reader) { Post result = null; if (reader.HasRows) { result = new Post( reader.GetInt32("idpost"), reader.GetDateTime("created"), reader.GetString("message")); } return result; }
public ActionResult Create(Post post) { if (!ModelState.IsValid) { return View("new", post); } post.Save(); if (!IsJsonRequest) return RedirectToAction("index"); else return Json(new { status = "success" }); }
public int Save(Post instance) { string cmdText = @" insert into posts (idpost, created, message) values (@idpost, @created, @message) on duplicate key update message=values(message)"; ulong id; ExecuteNonQuery( cmdText, "SaidWhat.Primary", CommandType.Text, new MySqlParameter[] { new MySqlParameter("@idpost", instance.IdPost), new MySqlParameter("@created", instance.Created), new MySqlParameter("@message", instance.Message) }, out id); return (int)id; }
public ActionResult New() { var model = new Post(); return View("new", model); }