Exemplo n.º 1
0
        public async Task <IActionResult> Create(CreateViewModel formPost)
        {
            if (ModelState.IsValid)
            {
                Post post = new Post();
                post.BlogId      = formPost.BlogId;
                post.PostId      = formPost.PostId;
                post.Title       = formPost.Title;
                post.Tags        = formPost.Tags;
                post.Content     = formPost.Content;
                post.DateCreated = DateTime.Now;
                post.LastUpdated = DateTime.Now;

                _context.Posts.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewData["BlogId"] = new SelectList(_context.Blogs, "BlogId", "Blog", formPost.BlogId);

            return(View(new CreateViewModel {
                TopLevelCategories = _context.Blogs.ToList()//.Where(p => p.BlogId == formPost.BlogId)
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Blogs.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(blog));
        }