Exemplo n.º 1
0
        public async Task <IActionResult> DeletePost([FromBody] DeletePostViewModel deletePostViewModel)
        {
            var callerId = await _authHelper.GetCallerId(_caller);

            if (await _authHelper.CheckIfUserIsBanned(callerId))
            {
                return(new BadRequestObjectResult(
                           new
                {
                    Message = "User currently bannend",
                    StatusCodes.Status403Forbidden
                }));
            }

            var result = await _postRepository.DeletePost(deletePostViewModel.PostId, callerId);

            _postFilesUploadHelper.DeleteFiles(result.Post);
            if (result.Successfull)
            {
                return(new OkObjectResult(new
                {
                    result
                }));
            }
            return(new BadRequestObjectResult(
                       new
            {
                result,
                StatusCodes.Status403Forbidden
            }));
        }
Exemplo n.º 2
0
        public ActionResult Delete(int id)
        {
            if ((bool)TempData["UserAccountSuspended"])
            {
                return(RedirectToAction("Suspended", "Account"));
            }

            var postService = new PostService();

            var result = postService.GetPostById(new GetPostByIdRequest {
                Id = id
            }).Post;

            var model = new DeletePostViewModel
            {
                Id            = result.Id,
                Title         = result.Title,
                Summary       = result.Summary,
                CategoryTitle = result.CategoryTitle,
                IsDraft       = result.IsDraft,
                Tags          = result.Tags
            };

            return(View(model));
        }
Exemplo n.º 3
0
 public ActionResult deletePost(string post_id, string receiver_id, DeletePostViewModel deletePostViewModel)
 {
     if (ModelState.IsValid)
     {
         var message = new Message()
         {
             sender_id = User.Identity.GetUserId(), receiver_id = receiver_id, content = deletePostViewModel.messageToUser, date = DateTime.Now, type = Convert.ToInt32(MessageTypes.adminWarning)
         };
         FacebookDatabaseEntities databaseEntities = new FacebookDatabaseEntities();
         Post post = new Post()
         {
             post_id = int.Parse(post_id)
         };
         databaseEntities.Posts.Attach(post);
         databaseEntities.Posts.Remove(post);
         databaseEntities.SaveChanges();
         MessageHandler.sendMessage(message);
         return(RedirectToAction("ShowMyProfile", "Profile"));
     }
     else
     {
         var post = databaseEntities.Posts.Find(int.Parse(post_id));
         return(View("DeletePage", new DeletePostViewModel(post)));
     }
 }
Exemplo n.º 4
0
        public ActionResult Delete(DeletePostViewModel model)
        {
            var isDeleted = postService.DeletePost(model.Id);

            if (isDeleted == false)
            {
                return(HttpNotFound());
            }

            return(this.RedirectToAction(c => c.Index()));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Delete(DeletePostViewModel model)
        {
            Result result = new Result(false, "Unable to delete post at this time.");

            if (ModelState.IsValid)
            {
                Post post = await _post.GetPostAndCommentsAsync(model.Id);

                post.IsActive            = false;
                post.RowModifiedBy       = Convert.ToInt32(_userManager.GetUserId(User));
                post.RowModifiedDateTime = DateTime.Now;

                if (post.Comments != null && post.Comments.Count() != 0)
                {
                    foreach (var comment in post.Comments)
                    {
                        comment.IsActive            = false;
                        comment.RowModifiedBy       = post.RowModifiedBy;
                        comment.RowModifiedDateTime = post.RowModifiedDateTime;

                        if (comment.Replies != null && comment.Replies.Count() != 0)
                        {
                            foreach (var reply in comment.Replies)
                            {
                                reply.IsActive            = false;
                                reply.RowModifiedBy       = post.RowModifiedBy;
                                reply.RowModifiedDateTime = post.RowModifiedDateTime;
                            }
                        }
                    }
                }

                try
                {
                    await _post.EditPostAsync(post);

                    result.Succeeded = true;
                    result.Message   = "Post deleted.";
                }
                catch (Exception ex)
                {
                    result.Message = "Unable to delete post at this time.";

                    SysException exception = new SysException(ex)
                    {
                        Url = UrlHelper.GetRequestUrl(HttpContext)
                    };
                }
            }

            return(Json(result));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Delete(DeletePostViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                this.TempData["InfoMessage"] = "Something went wrong!";
                return(this.View(model));
            }

            await this.postService.DeletePostAsync(model.Id);

            this.TempData["InfoMessage"] = "Post successfully deleted!";
            return(this.RedirectToAction("All", "Posts"));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Delete(int id = 0)
        {
            ViewData[Constants.FormSubmit] = new FormSubmit
            {
                Id        = id,
                Result    = null,
                CancelUrl = Url.Action(nameof(Edit), "Post", new { id }),
                DeleteUrl = Url.Action(nameof(Delete), "Post", new { id }),
                IndexUrl  = Url.Action(nameof(Index), "Post")
            };

            var post = await _post.GetPostAndCommentsAsync(id);

            DeletePostViewModel model = new DeletePostViewModel
            {
                Id                  = id,
                Title               = post.Title,
                Content             = post.Content,
                RowCreatedDateTime  = post.RowCreatedDateTime,
                RowModifiedDateTime = post.RowModifiedDateTime
            };

            if (post.Comments != null && post.Comments.Count() != 0)
            {
                model.Comments = new List <CommentViewModel>();

                for (int i = 0; i < post.Comments.Count(); i++)
                {
                    var comment = post.Comments.ElementAt(i);

                    var commentViewModel = _mapper.Map <Comment, CommentViewModel>(comment);
                    model.Comments.Add(commentViewModel);

                    if (comment.Replies != null & comment.Replies.Count() != 0)
                    {
                        model.Comments.ElementAt(i).Replies = new List <CommentViewModel>();

                        for (int j = 0; j < comment.Replies.Count(); j++)
                        {
                            var reply = comment.Replies.ElementAt(j);

                            var tempReply = _mapper.Map <Comment, CommentViewModel>(reply);
                            model.Comments.ElementAt(i).Replies.Add(tempReply);
                        }
                    }
                }
            }

            return(View(model));
        }
        public IActionResult Delete(Guid id)
        {
            var post = this.postRepository.GetById(id);

            if (null != post)
            {
                var viewModel = new DeletePostViewModel(post);
                return(View(viewModel));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 9
0
        public ActionResult Delete(DeletePostViewModel model)
        {
            if ((bool)TempData["UserAccountSuspended"])
            {
                return(RedirectToAction("Suspended", "Account"));
            }

            var postService = new PostService();

            var result = postService.DeletePost(new DeletePostRequest {
                Id = model.Id, IsComplaintOrVoteDifference = false
            });

            return(RedirectToAction("Index", "Post"));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Delete(int postId)
        {
            var post = await this.blogPostService.GetPostByIdAsync(postId);

            if (post == null)
            {
                return(NotFound());
            }

            var model = new DeletePostViewModel
            {
                PostId    = post.Id,
                PostTitle = post.Title
            };

            return(this.View(model));
        }
Exemplo n.º 11
0
        public IActionResult Delete(int id)
        {
            var post  = this.postsService.GetById(id);
            var model = new DeletePostViewModel
            {
                ForumId        = post.Forum.Id,
                PostId         = post.Id,
                PostAuthor     = post.User.UserName,
                PostContent    = post.Content,
                AuthorId       = post.User.Id,
                AuthorName     = post.User.UserName,
                AuthorImageUrl = post.User.ProfileImageUrl,
                AuthorRating   = post.User.Rating,
                CreatedOn      = post.CreatedOn,
                IsAuthorAdmin  = this.userManager.GetRolesAsync(post.User).Result.Contains("Administrator"),
            };

            return(this.View(model));
        }
Exemplo n.º 12
0
        public ActionResult Delete(DeletePostViewModel viewModel, string action)
        {
            try
            {
                if (action == "yes")
                {
                    viewModel.Delete();
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                while (ex != null)
                {
                    ModelState.AddModelError("", ex.Message);
                    ex = ex.InnerException;
                }
            }

            return(View());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> DeleteConfirm(DeletePostViewModel model, int postId)
        {
            var post = await this.blogPostService.GetPostByIdAsync(postId);

            if (post == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await this.blogPostService.DeletePost(post);

                this.TempData[BlogMessagesConstants.TEMPDATA_SUCCESS_MESSAGE] = $"Post '{post.Title}' {BlogMessagesConstants.POST_WAS_DELETED}";

                return(this.RedirectToAction(nameof(Index), new { area = AreaConstants.BLOG_AREA }));
            }
            else
            {
                return(View(model));
            }
        }
Exemplo n.º 14
0
 public ActionResult Delete(int id)
 {
     return(View(DeletePostViewModel.GetDetails(id)));
 }