コード例 #1
0
        public ActionResult Details(FormCollection input)
        {
            var viewModel = new CommentsDetailsViewModel {
                Comments = new List <CommentEntry>(), Options = new CommentDetailsOptions()
            };

            UpdateModel(viewModel);

            IEnumerable <CommentEntry> checkedEntries = viewModel.Comments.Where(c => c.IsChecked);

            switch (viewModel.Options.BulkAction)
            {
            case CommentDetailsBulkAction.None:
                break;

            case CommentDetailsBulkAction.Unapprove:
                if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
                {
                    return(new HttpUnauthorizedResult());
                }

                foreach (CommentEntry entry in checkedEntries)
                {
                    _commentService.UnapproveComment(entry.Comment.Id);
                }
                break;

            case CommentDetailsBulkAction.Approve:
                if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
                {
                    return(new HttpUnauthorizedResult());
                }

                foreach (CommentEntry entry in checkedEntries)
                {
                    _commentService.ApproveComment(entry.Comment.Id);
                }
                break;

            case CommentDetailsBulkAction.Delete:
                if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment")))
                {
                    return(new HttpUnauthorizedResult());
                }

                foreach (CommentEntry entry in checkedEntries)
                {
                    _commentService.DeleteComment(entry.Comment.Id);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public ActionResult Details(int id, CommentDetailsOptions options)
        {
            // Default options
            if (options == null)
            {
                options = new CommentDetailsOptions();
            }

            // Filtering
            IContentQuery <CommentPart, CommentPartRecord> comments;

            try {
                switch (options.Filter)
                {
                case CommentDetailsFilter.All:
                    comments = _commentService.GetCommentsForCommentedContent(id);
                    break;

                case CommentDetailsFilter.Approved:
                    comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Approved);
                    break;

                case CommentDetailsFilter.Pending:
                    comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Pending);
                    break;

                case CommentDetailsFilter.Spam:
                    comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Spam);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                var entries = comments.List().Select(comment => CreateCommentEntry(comment.Record)).ToList();
                var model   = new CommentsDetailsViewModel {
                    Comments = entries,
                    Options  = options,
                    DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id) == null ? "" : _commentService.GetDisplayForCommentedContent(id).DisplayText,
                    CommentedItemId             = id,
                    CommentsClosedOnItem        = _commentService.CommentsDisabledForCommentedContent(id),
                };
                return(View(model));
            } catch (Exception exception) {
                this.Error(exception, T("Listing comments failed: {0}", exception.Message), Logger, Services.Notifier);

                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
        public ActionResult Details(int id, CommentDetailsOptions options)
        {
            // Default options
            if (options == null)
            {
                options = new CommentDetailsOptions();
            }

            // Filtering
            IContentQuery <CommentPart, CommentPartRecord> comments;

            switch (options.Filter)
            {
            case CommentDetailsFilter.All:
                comments = _commentService.GetCommentsForCommentedContent(id);
                break;

            case CommentDetailsFilter.Approved:
                comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Approved);
                break;

            case CommentDetailsFilter.Pending:
                comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Pending);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            var entries = comments.List().Select(comment => CreateCommentEntry(comment)).ToList();
            var model   = new CommentsDetailsViewModel {
                Comments = entries,
                Options  = options,
                DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id) == null ? "" : _commentService.GetDisplayForCommentedContent(id).DisplayText,
                CommentedItemId             = id,
                CommentsClosedOnItem        = _commentService.CommentsDisabledForCommentedContent(id),
            };

            return(View(model));
        }
コード例 #4
0
        public async Task <IEnumerable <CommentsDetailsViewModel> > Latest3VehicleComments(string vehicleID)
        {
            var comments = await this.commentRepo.All().Where(x => x.VehicleID == vehicleID).OrderByDescending(x => x.DateAdded).Take(3).ToListAsync();

            var result = new List <CommentsDetailsViewModel>();

            foreach (var com in comments)
            {
                var user = await this.usersRepo.All().FirstOrDefaultAsync(x => x.Id == com.UserID);

                var mapped = new CommentsDetailsViewModel
                {
                    DateAdded   = com.DateAdded,
                    UserName    = user.UserName,
                    Description = com.Description,
                    Title       = com.Title,
                };

                result.Add(mapped);
            }

            return(result);
        }
コード例 #5
0
        public ActionResult Details(FormCollection input)
        {
            var viewModel = new CommentsDetailsViewModel {
                Comments = new List <CommentEntry>(), Options = new CommentDetailsOptions()
            };

            UpdateModel(viewModel);

            try {
                IEnumerable <CommentEntry> checkedEntries = viewModel.Comments.Where(c => c.IsChecked);
                switch (viewModel.Options.BulkAction)
                {
                case CommentDetailsBulkAction.None:
                    break;

                case CommentDetailsBulkAction.MarkAsSpam:
                    if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
                    {
                        return(new HttpUnauthorizedResult());
                    }
                    //TODO: Transaction
                    foreach (CommentEntry entry in checkedEntries)
                    {
                        _commentService.MarkCommentAsSpam(entry.Comment.Id);
                    }
                    break;

                case CommentDetailsBulkAction.Unapprove:
                    if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
                    {
                        return(new HttpUnauthorizedResult());
                    }

                    foreach (CommentEntry entry in checkedEntries)
                    {
                        _commentService.UnapproveComment(entry.Comment.Id);
                    }
                    break;

                case CommentDetailsBulkAction.Approve:
                    if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
                    {
                        return(new HttpUnauthorizedResult());
                    }

                    foreach (CommentEntry entry in checkedEntries)
                    {
                        _commentService.ApproveComment(entry.Comment.Id);
                    }
                    break;

                case CommentDetailsBulkAction.Delete:
                    if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment")))
                    {
                        return(new HttpUnauthorizedResult());
                    }

                    foreach (CommentEntry entry in checkedEntries)
                    {
                        _commentService.DeleteComment(entry.Comment.Id);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            } catch (Exception exception) {
                this.Error(exception, T("Editing comments failed: {0}", exception.Message), Logger, Services.Notifier);

                return(Details(viewModel.CommentedItemId, viewModel.Options));
            }

            return(RedirectToAction("Index"));
        }