Exemplo n.º 1
0
        /// <summary>
        /// Allows deletion of an individual snippet by the author.
        /// </summary>
        /// <param name="snippetId"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public bool DeleteSnippet(string snippetId, string sessionKey)
        {
            User user = this.ValidateToken(sessionKey);

            using (busCodeSnippet codeSnippet = CodePasteFactory.GetCodeSnippet())
            {
                if (codeSnippet.Load(snippetId) == null)
                {
                    this.ThrowException("Invalid snippet specified");
                }
                if (codeSnippet.Entity.UserId != user.Id)
                {
                    this.ThrowException("Access denied: You can only delete snippets you posted with this user account");
                }
                return(codeSnippet.Delete());
            }
        }
Exemplo n.º 2
0
        public bool RemoveSnippet(string snippetId)
        {
            using (busCodeSnippet Snippet = new busCodeSnippet())
            {
                if (Snippet.Load(snippetId) == null)
                {
                    throw new InvalidOperationException("Unable to delete snippet");
                }

                if (!AppUserState.IsAdmin && !this.IsEditAllowed(Snippet.Entity))
                {
                    throw new UnauthorizedAccessException("Unauthorized Access: You have to be signed in as an administrator in delete snippets.");
                }

                Snippet.Delete();
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool RemoveSnippet(string snippetId)
        {
            using (busCodeSnippet Snippet = new busCodeSnippet())
            {
                if (Snippet.Load(snippetId) == null)
                    throw new InvalidOperationException("Unable to delete snippet");

                if (!this.AppUserState.IsAdmin && !this.IsEditAllowed(Snippet.Entity))
                    throw new UnauthorizedAccessException("Unauthorized Access: You have to be signed in as an administrator in delete snippets.");

                Snippet.Delete();
            }

            return true;
        }