public ActionResult ComposePost(ForumModel model) { ForumRepository repository = new ForumRepository(); repository.AddPost(User.Identity.Name, model.title, model.content, model.courseId); return RedirectToAction("PostMessage"); }
public ActionResult ReadPost(ForumModel model) { ForumRepository repository = new ForumRepository(); repository.MarkRead(model.postId); return View(model); }
public ForumModel GetBy(int id) { ForumModel post = new ForumModel(); var sql = string.Format("SELECT * FROM PostTable WHERE PostId = '{0}'", id); var connectionString = "Server=(local);Database=Savnac.Database;Trusted_Connection=True;"; var command = new SqlCommand(sql, new SqlConnection(connectionString)); using (var connection = command.Connection) { connection.Open(); using (var reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { post = new ForumModel() { postId = (int)reader["postId"], title = reader["postTitle"].ToString(), content = reader["postContent"].ToString(), datePosted = (DateTime)reader["postTime"], courseId = (int)reader["courseId"], userName = reader["userName"].ToString(), isRead = (bool)reader["post_isRead"] }; } } return post; }