Ejemplo n.º 1
0
        public JsonResult DeleteAuthor(int userID, string token)
        {
            if (userID == 1 || !CheckToken(token))
            {
                throw new NotSupportedException("Cannot delete the admin");
            }

            try
            {
                var posts = _postRepository.GetPostsByUserID(userID, 1).Select(p => p.PostID).ToList();

                _categoryRepository.DeletePostCategoryMapping(posts);
                _tagRepository.DeleteTagsForsPosts(posts);
                _commentRepository.DeleteCommentsByPostID(posts);
                _postRepository.DeletePostsByUserID(userID);
                _roleRepository.DeleteRolesForUser(userID);
                _userRepository.DeleteUser(userID);
            }
            catch
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }