public async Task <IActionResult> PostComment(PostCommentViewModel vm) { if (!ModelState.IsValid) { return(RedirectToAction("Post", new { id = vm.PostId, slug = vm.PostSlug })); } else { var user = await _userManager.GetUserAsync(HttpContext.User); if (vm.MainCommentId == 0) { var comment = new PostMainComment { PostId = vm.PostId, PostSlug = vm.PostSlug, Message = vm.Message, CreatedDate = DateTime.Now, User = user }; _repo.AddPostMainComment(comment); string notifyMailText = EmailHelper.BuildTemplate(_templatesPath, "NewCommentTemplate.html"); notifyMailText = notifyMailText.Replace("[username]", user.UserName).Replace("[slug]", vm.PostSlug).Replace("[message]", vm.Message); await _emailService.SendAsync("*****@*****.**", "New Post Main Comment Added", notifyMailText, true); } else { var comment = new PostSubComment { PostMainCommentId = vm.MainCommentId, Message = vm.Message, CreatedDate = DateTime.Now, User = user }; _repo.AddPostSubComment(comment); string notifyMailText = EmailHelper.BuildTemplate(_templatesPath, "NewCommentTemplate.html"); notifyMailText = notifyMailText.Replace("[username]", user.UserName).Replace("[slug]", vm.MainCommentId.ToString()).Replace("[message]", vm.Message); await _emailService.SendAsync("*****@*****.**", "New Post Sub Comment Added", notifyMailText, true); } await _repo.SaveChangesAsync(); return(RedirectToAction("Post", new { id = vm.PostId, slug = vm.PostSlug })); } }
//Post Sub Comment methods public void AddPostSubComment(PostSubComment comment) { _ctx.PostSubComments.Add(comment); }