Ejemplo n.º 1
0
        public object SaveComment(string commentText, string snippetId)
        {
            if (string.IsNullOrEmpty(commentText))
            {
                throw new InvalidOperationException("Please enter some comment text before submitting.");
            }

            using (busCodeSnippet Snippet = new busCodeSnippet())
            {
                if (Snippet.Load(snippetId) == null)
                {
                    throw new InvalidOperationException("Invalid snippet specified");
                }

                if (string.IsNullOrEmpty(this.AppUserState.Name))
                {
                    throw new UnauthorizedAccessException("You have to be signed in in order to add comments.");
                }

                if (!Snippet.AddComment(commentText, this.AppUserState.UserId))
                {
                    throw new ApplicationException("Couldn't add comment: " + Snippet.ErrorMessage);
                }
            }

            return(new
            {
                commentText = HtmlUtils.DisplayMemoEncoded(commentText),
                headerText = "by " + this.AppUserState.Name + "  " + TimeUtils.FriendlyDateString(DateTime.Now, true)
            });
        }
Ejemplo n.º 2
0
        public object SaveComment(string commentText, string snippetId)
        {
            if (string.IsNullOrEmpty(commentText))
                throw new InvalidOperationException("Please enter some comment text before submitting.");

            using (busCodeSnippet Snippet = new busCodeSnippet())
            {
                if (Snippet.Load(snippetId) == null)
                    throw new InvalidOperationException("Invalid snippet specified");

                if (string.IsNullOrEmpty(this.AppUserState.Name))
                    throw new UnauthorizedAccessException("You have to be signed in in order to add comments.");

                if (!Snippet.AddComment(commentText, this.AppUserState.UserId))
                    throw new ApplicationException("Couldn't add comment: " + Snippet.ErrorMessage);
            }

            return  new
            {
                commentText = HtmlUtils.DisplayMemoEncoded(commentText),
                headerText = "by " + this.AppUserState.Name + "  " + TimeUtils.FriendlyDateString(DateTime.Now,true)
            };
        }