예제 #1
0
        public ActionResult AddBlog(BlogObj newBlog)
        {
            var postDB = new Blog()
            {
                Post = newBlog.Post
            };

            _context.Blogs.Add(postDB);

            try
            {
                _context.SaveChanges();
                return(View("DisplayBlogs"));
            }
            catch (DbUpdateException e)
            {
                return(View("Blog"));
            }
        }
예제 #2
0
        public ActionResult DisplayBlogs()
        {
            var blogs = new BlogObj();

            blogs.Posts = new List <BlogObj>();

            var query =
                from c in _context.Blogs
                select c;

            foreach (var post in query)
            {
                var postDb = new BlogObj
                {
                    Post = post.Post
                };

                blogs.Posts.Add(postDb);
            }

            return(View(blogs));
        }
예제 #3
0
        // GET: Blog
        public ActionResult Blog()
        {
            var obj = new BlogObj();

            return(View(obj));
        }