コード例 #1
0
        public ActionResult DeletePost(int postId)
        {
            var currentUserId = User.Identity.GetUserId <int>();

            if (currentUserId == 0)
            {
                return new JsonResult {
                           Data = new { success = false, responseText = "You can't delete post - You not authorized. Please, contact with administrator." }
                }
            }
            ;

            if (!_permissionsService.UserHasPermissionByForumId(currentUserId, 8, CommonConstants.ShowAdminControls))//todo change check to Admin group, not to permisson
            {
                return new JsonResult {
                           Data = new { success = false, responseText = "You can't delete post - you have not permisson. Please, contact with administrator." }
                }
            }
            ;

            if (_adminService.DeletePost(postId))
            {
                return(new JsonResult {
                    Data = new { success = true, responseText = "Post was deleted." }
                });
            }
            return(new JsonResult {
                Data = new { success = false, responseText = "Post wasn't deleted. Please, contact with administrator." }
            });
        }
コード例 #2
0
        public JsonResult CheckNewPostPermissions(int topicId)
        {
            var userId = User.Identity.GetUserId <int>();

            if (userId == 0)
            {
                return new JsonResult {
                           Data = new { success = false, responseText = "You can't create post - You not authorized. Please, contact with administrator." }
                }
            }
            ;

            var topicInfoViewModel = _topicReadService.GetTopicInfoViewModelById(topicId);
            var permission         = _permissionsService.UserHasPermissionByForumId(userId, topicInfoViewModel.ForumId, topicInfoViewModel.TopicClosed
                ? new List <string>()
            {
                CommonConstants.PostMessageInClosedTopic
            }
                : new List <string>()
            {
                CommonConstants.PostMessageInOpenTopic
            });

            return(!permission ? new JsonResult {
                Data = new { success = false, responseText = "You can't create post in this topic. Please, contact with administrator." }
            }
                               : new JsonResult {
                Data = new { success = true }
            });
        }