public async Task <IActionResult> Comment(CommentViewModel commentViewModel) { if (!ModelState.IsValid) { return(RedirectToAction("Post", new { Id = commentViewModel.PostId })); } var post = _repo.GetRiddle(commentViewModel.PostId); if (commentViewModel.MainCommentId == 0) { post.MainComments = post.MainComments ?? new List <MainComment>(); post.MainComments.Add(new MainComment { Message = commentViewModel.Message, Created = DateTime.Now }); _repo.Update(post); } else { var comment = new SubComment { MainCommentId = commentViewModel.MainCommentId, Message = commentViewModel.Message, Created = DateTime.Now }; _repo.AddSubComment(comment); } await _repo.SaveChangesAsync(); return(RedirectToAction("Post", new { Id = commentViewModel.PostId })); }
public async Task <IActionResult> Edit(RiddlePost riddlePost) { if (riddlePost.Id > 0) { _repo.Update(riddlePost); } else { _repo.Add(riddlePost); } if (await _repo.SaveChangesAsync()) { return(RedirectToAction("Index")); } else { return(View(riddlePost)); } }