public DeleteCommentViewModel GetDeleteVm(int id)
        {
            Comment comment = this.Context.Comments.FirstOrDefault(c => c.Id == id);
            DeleteCommentViewModel modelComment = Mapper.Map <Comment, DeleteCommentViewModel>(comment);

            return(modelComment);
        }
示例#2
0
        public JsonResult DeleteComment(DeleteCommentViewModel model)
        {
            var comment = commentService.GetById(model.Id);

            if (comment == null)
            {
                return(NotFound("Comment to delete not found"));
            }
            //If author is deleting his comment, or some of admin trying to delete it
            if (User.IsInRole("admin") ||
                User.IsInRole("superadmin") ||
                User.IsInRole("moderator") ||
                userService.GetUserById(model.AuthorId) == userService.GetUserByEmail(User.Identity.Name))
            {
                var result = commentService.Delete(model.Id);
                if (result.Succedeed)
                {
                    return(GetJson(commentService.GetTopicComments(model.TopicId)));
                }
                return(ServerError(result.Message));
            }
            else
            {
                Response.StatusCode = 401;
                return(GetJson(new { message = "Unauthorized" }));
            }
        }
        public async Task <ResponseDeleteCommentViewModel> Delete(DeleteCommentViewModel model)
        {
            if (!model.AuthenticatedMode || string.IsNullOrEmpty(model.Id) || string.IsNullOrEmpty(model.Token) || string.IsNullOrEmpty(model.SourcePlatform) ||
                string.IsNullOrWhiteSpace(model.CommentId))
            {
                return(new ResponseDeleteCommentViewModel(ResponseDeleteCommentViewModel.OperationResult.Invalid));
            }

            if (!(await _authorizationService.AuthorizeAsync(null, model, new Requirements.AuthorizedUserRequirement())))
            {
                return(new ResponseDeleteCommentViewModel(ResponseDeleteCommentViewModel.OperationResult.AuthorizationFailed));
            }

            var comment = await _dbContext.Comments.Include(c => c.Page).SingleOrDefaultAsync(c => c.Id == model.CommentId && c.AuthorId == model.Id);

            if (comment == null)
            {
                return(new ResponseDeleteCommentViewModel(ResponseDeleteCommentViewModel.OperationResult.AuthorizationFailed));
            }

            comment.Content = null;

            comment.Page.CommentsCount--;
            //Update comment
            _dbContext.Comments.Update(comment);
            //Update Page
            _dbContext.Pages.Update(comment.Page);
            //Save changes
            await _dbContext.SaveChangesAsync();

            return(new ResponseDeleteCommentViewModel(ResponseDeleteCommentViewModel.OperationResult.CommentDeleted));
        }
        private bool IsUserAuthorizedToDelete(DeleteCommentViewModel deleteCommentViewModel)
        {
            bool isAdmin  = this.User.IsInRole("Admin");
            bool isAuthor = deleteCommentViewModel.IsAuthor();

            return(isAdmin || isAuthor);
        }
示例#5
0
        public async Task DeleteComment(DeleteCommentViewModel model)
        {
            try
            {
                if (_projectDal.DeleteComment(model.CommentId))
                {
                    await Clients.All.SendAsync("DeletedComment", JsonConvert.SerializeObject(model));

                    await Clients.Caller.SendAsync("SuccessfullDelete");
                }
            } catch (Exception e)
            {
                await Clients.Caller.SendAsync("ErrorWhileDeleting", e);
            }
        }
示例#6
0
        public async Task <JsonResult> DeleteComment([FromBody] DeleteCommentViewModel obj)
        {
            if (ModelState.IsValid)
            {
                var comment = await _commentRepository.FetchByCriteria(m => m.Id == obj.CommentId).SingleOrDefaultAsync();

                if (comment != null)
                {
                    await RemoveChildren(comment.Id);

                    _commentRepository.Remove(comment);
                    await _commentRepository.SaveChangesAsync();
                }
                if (Request.IsAjaxRequest())
                {
                    return(Json(1));
                }
            }
            return(Json(new { code = 0 }));
        }
示例#7
0
        public IActionResult DeleteComment(int commentId)
        {
            var currUser = this.UserAccountService.GetCurrentUser(HttpContext);

            var comment = this.CommentService.GetCommentById(commentId);

            var commentOwnerId = comment.WAGUserId;

            var deleteCommentViewModel = new DeleteCommentViewModel();

            if (currUser.Id == commentOwnerId || User.IsInRole(GlobalConstants.AdminRole))
            {
                this.CommentService.DeleteComment(commentId);

                deleteCommentViewModel.CommentId = commentId;
            }

            string json = JsonConvert.SerializeObject(deleteCommentViewModel);

            return(Json(json));
        }
示例#8
0
        public async Task <ActionResult> Delete(DeleteCommentViewModel model)
        {
            var request = new DeleteNotificationComment(model.CommentId);

            await this.mediator.SendAsync(request);

            DateTime startDate      = new DateTime();
            DateTime endDate        = new DateTime();
            int?     shipmentNumber = null;
            string   user           = string.Empty;

            GetFilteredTempData(model.Filter, out startDate, out endDate, out shipmentNumber, out user);

            var comments = await this.mediator.SendAsync(new GetNotificationComments(model.NotificationId, model.Type, model.Page, startDate, endDate, shipmentNumber, user));

            if (comments.NotificationComments.Count == 0 && model.Page > 1)
            {
                model.Page--;
            }

            return(RedirectToAction("Index", new { id = model.NotificationId, type = model.Type, page = model.Page, filter = model.Filter }));
        }
示例#9
0
        public async Task <ActionResult> Delete(Guid id, Guid commentId, NotificationShipmentsCommentsType type, string filter, int page = 1)
        {
            DateTime startDate      = new DateTime();
            DateTime endDate        = new DateTime();
            int?     shipmentNumber = null;
            string   user           = string.Empty;

            GetFilteredTempData(filter, out startDate, out endDate, out shipmentNumber, out user);

            var comments = await this.mediator.SendAsync(new GetNotificationComments(id, type, page, startDate, endDate, shipmentNumber, user));

            DeleteCommentViewModel model = new DeleteCommentViewModel()
            {
                NotificationId = id,
                CommentId      = commentId,
                Comment        = comments.NotificationComments.FirstOrDefault(p => p.CommentId == commentId),
                Type           = type,
                Page           = page
            };

            return(View(model));
        }
示例#10
0
 public JsonResult DeleteComment([FromBody] DeleteCommentViewModel deleteCommentViewModel)
 {
     try
     {
         var     post    = postService.Get(deleteCommentViewModel.PostId);
         Comment comment = post.Comments.Single(u => u.Id == deleteCommentViewModel.CommentId);
         if (post.UserId == deleteCommentViewModel.UserId || deleteCommentViewModel.UserId == comment.UserId)
         {
             post.Comments.Remove(comment);
         }
         postService.Update(post.Id, post);
         return(Json(new
         {
             isValid = true,
         }));
     }
     catch
     {
         return(Json(new
         {
             isValid = false
         }));
     }
 }
示例#11
0
 public IActionResult DeleteComment(DeleteCommentViewModel model)
 {
     repository.DeleteComment(model.CommentID);
     return(Json(""));
 }
 public ActionResult Delete(DeleteCommentViewModel viewModel)
 {
     this.commentService.DeleteComment(viewModel.CommentId);
     return(RedirectToAction("Details", "Item", new { itemId = viewModel.ItemId }));
 }
示例#13
0
        public ActionResult DeleteComment(int id)
        {
            DeleteCommentViewModel model = this.service.GetDeleteVm(id);

            return(this.View(model));
        }