public async Task <IActionResult> PortfolioItemComment(PortfolioItemCommentViewModel vm) { if (!ModelState.IsValid) { return(RedirectToAction("PortfolioItem", new { id = vm.PortfolioItemId, slug = vm.PortfolioItemSlug })); } else { var user = await _userManager.GetUserAsync(HttpContext.User); if (vm.MainCommentId == 0) { var comment = new PortfolioItemMainComment { PortfolioItemId = vm.PortfolioItemId, PortfolioItemSlug = vm.PortfolioItemSlug, Message = vm.Message, CreatedDate = DateTime.Now, User = user }; _repo.AddPortfolioItemMainComment(comment); string notifyMailText = EmailHelper.BuildTemplate(_templatesPath, "NewCommentTemplate.html"); notifyMailText = notifyMailText.Replace("[username]", user.UserName).Replace("[slug]", vm.PortfolioItemSlug).Replace("[message]", vm.Message); await _emailService.SendAsync("*****@*****.**", "New Portfolio Main Comment Added", notifyMailText, true); } else { var comment = new PortfolioItemSubComment { PortfolioItemMainCommentId = vm.MainCommentId, Message = vm.Message, CreatedDate = DateTime.Now, User = user }; _repo.AddPortfolioItemSubComment(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 Portfolio Sub Comment Added", notifyMailText, true); } await _repo.SaveChangesAsync(); return(RedirectToAction("PortfolioItem", new { id = vm.PortfolioItemId, slug = vm.PortfolioItemSlug })); } }
//Portfolio Item Sub Comment methods public void AddPortfolioItemSubComment(PortfolioItemSubComment comment) { _ctx.PortfolioItemSubComments.Add(comment); }