Beispiel #1
0
        public async Task <IActionResult> DeletePortfolioItemMainComment(int id)
        {
            var  maincomment = _repo.GetPortfolioItemMainComment(id);
            bool hasSubs     = maincomment.SubComments.Count() > 0;

            if (hasSubs == true)
            {
                var comment = new PortfolioItemMainComment
                {
                    Id              = maincomment.Id,
                    CreatedDate     = maincomment.CreatedDate,
                    Message         = "This comment has been removed.",
                    UserId          = null,
                    PortfolioItemId = maincomment.PortfolioItemId
                };
                _repo.UpdatePortfolioItemMainComment(comment);
            }
            else
            {
                _repo.DeletePortfolioItemMainComment(id);
            }
            await _repo.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        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 }));
            }
        }
Beispiel #3
0
 //Used only to change a portfolio main comment to a blank if user/admin want to delete the comment and
 //it has sub comments, so sub comments aren't lost on a thread.
 public void UpdatePortfolioItemMainComment(PortfolioItemMainComment comment)
 {
     _ctx.PortfolioItemMainComments.Update(comment);
 }
Beispiel #4
0
 //Portfolio Item Main comment methods
 public void AddPortfolioItemMainComment(PortfolioItemMainComment comment)
 {
     _ctx.PortfolioItemMainComments.Add(comment);
 }
Beispiel #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            RequirePassword = await _userManager.HasPasswordAsync(user);

            if (RequirePassword)
            {
                if (!await _userManager.CheckPasswordAsync(user, Input.Password))
                {
                    ModelState.AddModelError(string.Empty, "Incorrect password.");
                    return(Page());
                }
            }
            //For deleting user comments
            var model = new ApplicationUser()
            {
                UserPostMainComments          = _repo.GetAllPostMainComments(user.Id),
                UserPostSubComments           = _repo.GetAllPostSubComments(user.Id),
                UserPortfolioItemMainComments = _repo.GetAllPortfolioItemMainComments(user.Id),
                UserPortfolioItemSubComments  = _repo.GetAllPortfolioItemSubComments(user.Id)
            };

            foreach (var comment in model.UserPostSubComments)
            {
                _repo.DeletePostSubComment(comment.Id);
                await _repo.SaveChangesAsync();
            }
            ;
            foreach (var comment in model.UserPostMainComments)
            {
                var  maincomment = _repo.GetPostMainComment(comment.Id);
                bool hasSubs     = maincomment.SubComments.Count() > 0;

                if (hasSubs == true)
                {
                    var mc = new PostMainComment
                    {
                        Id          = maincomment.Id,
                        CreatedDate = maincomment.CreatedDate,
                        Message     = "This comment has been removed.",
                        UserId      = null,
                        PostId      = maincomment.PostId
                    };
                    _repo.UpdatePostMainComment(mc);
                }
                else
                {
                    _repo.DeletePostMainComment(comment.Id);
                }
                await _repo.SaveChangesAsync();
            }
            ;
            foreach (var comment in model.UserPortfolioItemSubComments)
            {
                _repo.DeletePortfolioItemSubComment(comment.Id);
                await _repo.SaveChangesAsync();
            }
            ;
            foreach (var comment in model.UserPortfolioItemMainComments)
            {
                var  maincomment = _repo.GetPortfolioItemMainComment(comment.Id);
                bool hasSubs     = maincomment.SubComments.Count() > 0;

                if (hasSubs == true)
                {
                    var mc = new PortfolioItemMainComment
                    {
                        Id              = maincomment.Id,
                        CreatedDate     = maincomment.CreatedDate,
                        Message         = "This comment has been removed.",
                        UserId          = null,
                        PortfolioItemId = maincomment.PortfolioItemId
                    };
                    _repo.UpdatePortfolioItemMainComment(mc);
                }
                else
                {
                    _repo.DeletePortfolioItemMainComment(comment.Id);
                }
                await _repo.SaveChangesAsync();
            }
            ;

            var result = await _userManager.DeleteAsync(user);

            var userId = await _userManager.GetUserIdAsync(user);

            if (!result.Succeeded)
            {
                throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
            }

            await _signInManager.SignOutAsync();

            _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);

            return(Redirect("~/"));
        }