public async Task <IActionResult> Edit(EditViewModel 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.LastUpdated = DateTime.Now; _context.Update(post); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["BlogId"] = new SelectList(_context.Blogs, "BlogId", "Blog", formPost.BlogId); return(View(new EditViewModel { PostId = formPost.PostId, Title = formPost.Title, Content = formPost.Content, DateCreated = formPost.DateCreated, LastUpdated = formPost.LastUpdated, Tags = formPost.Tags, BlogId = formPost.BlogId, TopLevelCategories = _context.Blogs.ToList() })); }
public async Task <IActionResult> Edit(EditViewModel formBlog) { if (ModelState.IsValid) { //Status data from checkbox must be converted to Status enum Status status = StatusHelper.ToStatus(formBlog.Active); Blog blog = new Blog(); blog.BlogId = formBlog.BlogId; blog.Category = formBlog.Category; blog.Status = status; _context.Update(blog); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(new EditViewModel { BlogId = formBlog.BlogId, Active = formBlog.Active, Category = formBlog.Category })); }