Exemplo n.º 1
0
        public ActionResult ModeratePost(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var post        = _postService.Get(viewModel.PostId);
                    var permissions = RoleService.GetPermissions(post.Topic.Category, UsersRole);
                    if (!permissions[SiteConstants.Instance.PermissionEditPosts].IsTicked)
                    {
                        return(Content(LocalizationService.GetResourceString("Errors.NoPermission")));
                    }

                    if (viewModel.IsApproved)
                    {
                        post.Pending = false;
                    }
                    else
                    {
                        _postService.Delete(post, unitOfWork, false);
                    }

                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Content(ex.Message));
                }
            }

            return(Content("allgood"));
        }
Exemplo n.º 2
0
        public ActionResult ModeratePost(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var post   = _postService.Get(viewModel.PostId);
                    var postId = post.Id;

                    if (viewModel.IsApproved)
                    {
                        post.Pending = false;
                    }
                    else
                    {
                        _postService.Delete(post);
                    }

                    unitOfWork.Commit();

                    if (_luceneService.CheckIndexExists() && !viewModel.IsApproved)
                    {
                        _luceneService.Delete(postId);
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Content("error"));
                }
            }

            return(Content("allgood"));
        }
Exemplo n.º 3
0
        public ActionResult ModeratePost(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {

                try
                {
                    var post = _postService.Get(viewModel.PostId);
                    var permissions = RoleService.GetPermissions(post.Topic.Category, UsersRole);
                    if (!permissions[SiteConstants.Instance.PermissionEditPosts].IsTicked)
                    {
                        return Content(LocalizationService.GetResourceString("Errors.NoPermission"));
                    }

                    if (viewModel.IsApproved)
                    {
                        post.Pending = false;
                    }
                    else
                    {
                        _postService.Delete(post, unitOfWork, false);
                    }

                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return Content(ex.Message);
                }
            }

            return Content("allgood");
        }
Exemplo n.º 4
0
        public ActionResult ModerateTopic(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var topic      = _topicService.Get(viewModel.TopicId);
                    var postIdList = new List <Guid>();

                    if (viewModel.IsApproved)
                    {
                        topic.Pending = false;
                    }
                    else
                    {
                        var postId      = topic.LastPost.Id;
                        var post        = _postService.Get(postId);
                        var deleteTopic = _postService.Delete(post);

                        unitOfWork.SaveChanges();

                        if (deleteTopic)
                        {
                            postIdList = topic.Posts.Select(x => x.Id).ToList();
                            _topicService.Delete(topic);
                        }
                    }

                    // We use temp data because we are doing a redirect
                    //TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                    //{
                    //    Message = "Category Created",
                    //    MessageType =
                    //        GenericMessages.success
                    //};
                    unitOfWork.Commit();

                    // Delete the topic posts if
                    if (_luceneService.CheckIndexExists() && !viewModel.IsApproved)
                    {
                        foreach (var guid in postIdList)
                        {
                            _luceneService.Delete(guid);
                        }
                    }
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Content("error"));
                }
            }

            return(Content("allgood"));
        }
Exemplo n.º 5
0
        public virtual async Task <ActionResult> ModerateTopicAsync(ModerateActionViewModel viewModel, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                User.GetMembershipUser(MembershipService);
                var loggedOnUsersRole = LoggedOnReadOnlyUser.GetRole(RoleService);

                var topic       = _topicService.Get(viewModel.TopicId);
                var permissions = RoleService.GetPermissions(topic.Group, loggedOnUsersRole);

                // Is this user allowed to moderate - We use EditPosts for now until we change the permissions system
                if (!permissions[ForumConfiguration.Instance.PermissionEditPosts].IsTicked)
                {
                    return(Content(LocalizationService.GetResourceString("Errors.NoPermission")));
                }

                if (viewModel.IsApproved)
                {
                    topic.Pending = false;
                    _activityService.TopicCreated(topic);
                }
                else
                {
                    var topicResult = await _topicService.Delete(topic);

                    if (!topicResult.Successful)
                    {
                        return(Content(topicResult.ProcessLog.FirstOrDefault()));
                    }
                }

                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                return(Content(ex.Message));
            }


            return(Content("allgood"));
        }
Exemplo n.º 6
0
        public ActionResult ModerateTopic(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var topic = _topicService.Get(viewModel.TopicId);

                    if (viewModel.IsApproved)
                    {
                        topic.Pending = false;
                    }
                    else
                    {
                        var postId      = topic.LastPost.Id;
                        var post        = _postService.Get(postId);
                        var deleteTopic = _postService.Delete(post);

                        unitOfWork.SaveChanges();

                        if (deleteTopic)
                        {
                            _topicService.Delete(topic);
                        }
                    }

                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Content("error"));
                }
            }

            return(Content("allgood"));
        }
        public ActionResult ModerateTopic(ModerateActionViewModel viewModel)
        {
            try
            {
                var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService);
                var loggedOnUsersRole    = loggedOnReadOnlyUser.GetRole(RoleService);

                var topic       = _topicService.Get(viewModel.TopicId);
                var permissions = RoleService.GetPermissions(topic.Category, loggedOnUsersRole);

                // Is this user allowed to moderate - We use EditPosts for now until we change the permissions system
                if (!permissions[SiteConstants.Instance.PermissionEditPosts].IsTicked)
                {
                    return(Content(LocalizationService.GetResourceString("Errors.NoPermission")));
                }

                if (viewModel.IsApproved)
                {
                    topic.Pending = false;
                    _activityService.TopicCreated(topic);
                }
                else
                {
                    _topicService.Delete(topic);
                }

                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                return(Content(ex.Message));
            }


            return(Content("allgood"));
        }
Exemplo n.º 8
0
        public virtual ActionResult ModeratePost(ModerateActionViewModel viewModel)
        {
            try
            {
                User.GetMembershipUser(MembershipService);
                var loggedOnUsersRole = LoggedOnReadOnlyUser.GetRole(RoleService);

                var post        = _postService.Get(viewModel.PostId);
                var permissions = RoleService.GetPermissions(post.Topic.Group, loggedOnUsersRole);
                if (!permissions[ForumConfiguration.Instance.PermissionEditPosts].IsTicked)
                {
                    return(Content(LocalizationService.GetResourceString("Errors.NoPermission")));
                }

                if (viewModel.IsApproved)
                {
                    post.Pending = false;
                    _activityService.PostCreated(post);
                }
                else
                {
                    _postService.Delete(post, false);
                }

                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                return(Content(ex.Message));
            }


            return(Content("allgood"));
        }
Exemplo n.º 9
0
        public ActionResult ModerateTopic(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var topic       = _topicService.Get(viewModel.TopicId);
                    var permissions = RoleService.GetPermissions(topic.Category, UsersRole);

                    // Is this user allowed to moderate - We use EditPosts for now until we change the permissions system
                    if (!permissions[SiteConstants.Instance.PermissionEditPosts].IsTicked)
                    {
                        return(Content(LocalizationService.GetResourceString("Errors.NoPermission")));
                    }

                    if (viewModel.IsApproved)
                    {
                        topic.Pending = false;
                    }
                    else
                    {
                        _topicService.Delete(topic, unitOfWork);
                    }

                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return(Content(ex.Message));
                }
            }

            return(Content("allgood"));
        }
Exemplo n.º 10
0
        public ActionResult ModerateTopic(ModerateActionViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var topic = _topicService.Get(viewModel.TopicId);
                    var permissions = RoleService.GetPermissions(topic.Category, UsersRole);

                    // Is this user allowed to moderate - We use EditPosts for now until we change the permissions system
                    if (!permissions[SiteConstants.Instance.PermissionEditPosts].IsTicked)
                    {
                        return Content(LocalizationService.GetResourceString("Errors.NoPermission"));
                    }

                    if (viewModel.IsApproved)
                    {
                        topic.Pending = false;
                    }
                    else
                    {
                        _topicService.Delete(topic, unitOfWork);
                    }

                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    return Content(ex.Message);
                }
            }

            return Content("allgood");
        }