public async Task <IActionResult> CommentPost([Bind("Comment, CommentersName")] CommentViewModel commentViewModel, int?id) { if (!ModelState.IsValid) { return(View()); } var Person = _context.People .Where(p => p.Name == commentViewModel.CommentersName) .FirstOrDefault(); var Post = await _context.Posts.FirstOrDefaultAsync(p => p.Id == id); Post.Comments.Add(commentViewModel.Comment); if (Person == null) { var newPerson = new Person { Name = commentViewModel.CommentersName }; newPerson.Comments.Add(commentViewModel.Comment); _context.People.Add(newPerson); } else { Person.Comments.Add(commentViewModel.Comment); } _context.Comments.Add(commentViewModel.Comment); await _context.SaveChangesAsync(); return(RedirectToAction("Messageboard", "Messageboard")); }
public async Task <IActionResult> Messageboard(int?id) { if (!ModelState.IsValid) { return(View()); } int?Id = id; await _context.SaveChangesAsync(); return(RedirectToAction("Comment", "Comment", new { id = Id })); }