Exemplo n.º 1
0
        public ActionResult Index()
        {
            CommentsPortal commentsPortal = new CommentsPortal();
            Comments       comments       = new Comments();

            comments.getAllDetails = commentsPortal.selectAll();

            return(View(comments));
        }
Exemplo n.º 2
0
        public ActionResult Create(FormCollection collection)
        {
            Comments comments = new Comments
            {
                name = collection["name"],
                date = DateTime.Now,
                body = collection["body"]
            };
            string query = "insert into comments values(@name,@date,@body)";

            using (SqlConnection conn = new SqlConnection(cs))
            {
                SqlCommand sqlCommand = new SqlCommand(query, conn);
                sqlCommand.Parameters.AddWithValue("@name", comments.name);
                sqlCommand.Parameters.AddWithValue("@date", comments.date);
                sqlCommand.Parameters.AddWithValue("@body", comments.body);
                conn.Open();
                sqlCommand.ExecuteNonQuery();
            }
            CommentsPortal commentsPortal = new CommentsPortal();

            comments.getAllDetails = commentsPortal.selectAll();
            return(View("Index", comments));
        }