/// <summary>Takes an AkismetComment object and returns an (escaped) string of data to POST.</summary>
        /// <param name="comment">AkismetComment object to translate.</param>
        /// <returns>A System.String containing the data to POST to Akismet API.</returns>
        private string CreateData(AkismetComment comment)
        {
            string value = String.Format("blog={0}&user_ip={1}&user_agent={2}&referrer={3}&permalink={4}&comment_type={5}" +
                "&comment_author={6}&comment_author_email={7}&comment_author_url={8}&comment_content={9}",
                HttpUtility.UrlEncode(comment.Blog),
                HttpUtility.UrlEncode(comment.UserIp),
                HttpUtility.UrlEncode(comment.UserAgent),
                HttpUtility.UrlEncode(comment.Referrer),
                HttpUtility.UrlEncode(comment.Permalink),
                HttpUtility.UrlEncode(comment.CommentType),
                HttpUtility.UrlEncode(comment.CommentAuthor),
                HttpUtility.UrlEncode(comment.CommentAuthorEmail),
                HttpUtility.UrlEncode(comment.CommentAuthorUrl),
                HttpUtility.UrlEncode(comment.CommentContent)
            );

            return value;
        }
        public ActionResult Submit(CommentModel model)
        {
            var contentService = RuntimeContext.Instance.ContentService;

            var modelContent = contentService.GetContent(System.Web.HttpContext.Current);

            var newModel = Mapper.Map<CommentModel>(modelContent);
            newModel = Mapper.Map(newModel, model);

            if (ModelState.IsValid)
            {
                var akismet = new Akismet(ConfigurationManager.AppSettings["AkismetKey"], "http://blog.darren-ferguson.com/", "Joel.Net's Akismet API/1.0");

                var isSpam = true;

                try
                {
                    var verifyKey = akismet.VerifyKey();

                    if (verifyKey)
                    {
                        var akismetComment = new AkismetComment();
                        akismetComment.Blog = "http://blog.darren-ferguson.com/";
                        akismetComment.UserIp = Request.ServerVariables["REMOTE_ADDR"];
                        akismetComment.UserAgent = Request.ServerVariables["HTTP_USER_AGENT"];
                        akismetComment.CommentAuthor = model.CommentName;
                        akismetComment.CommentAuthorEmail = model.CommentEmail;
                        akismetComment.CommentAuthorUrl = "";
                        akismetComment.CommentType = "comment";
                        akismetComment.CommentContent = model.CommentMessage;

                        isSpam = akismet.CommentCheck(akismetComment);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    isSpam = true;
                }

                if (!string.IsNullOrEmpty(model.Moriyama))
                {
                    isSpam = true;
                }

                if (!isSpam)
                {
                    var stripper = new HtmlTagStripper(new[] { "p", "em", "b", "i", "u" });
                    model.CommentMessage = stripper.RemoveUnwantedTags(model.CommentMessage);
                    model.CommentMessage = model.CommentMessage.Replace(Environment.NewLine, "<br/>");

                    model.CommentName = model.CommentName.RemoveNonAlphaNumeric();

                    var commentId = Guid.NewGuid().ToString();
                    var contentUrl = contentService.GetContentUrl(System.Web.HttpContext.Current);

                    commentId = contentUrl + "/" + commentId + "/";

                    var properties = new Dictionary<string, object>
                    {
                        {"name", model.CommentName},
                        {"email", model.CommentEmail},
                        {"bodyText", model.CommentMessage}
                    };

                    try
                    {
                        var email = new CommentEmail
                        {
                            Email = model.CommentEmail,
                            Name = model.CommentName,
                            Comment = model.CommentMessage
                        };

                        email.Send();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);
                        ModelState.AddModelError("", "Your comment can't be added at this time.");
                        return View(modelContent.View(), newModel);
                    }

                    var ugc = contentService.CreateContent(commentId, properties);

                    ugc.Name = model.CommentEmail;
                    ugc.Type = "BlogComment";
                    ugc.Level = modelContent.Level + 1;
                    ugc.SortOrder = modelContent.Children().Count();

                    contentService.AddContent(ugc);

                    // Remove the post and the homepage from the output cache.
                    HttpResponse.RemoveOutputCacheItem(modelContent.RelativeUrl);
                    HttpResponse.RemoveOutputCacheItem(modelContent.Home().RelativeUrl);

                    //Analytics.Client.Identify(model.CommentEmail, new Traits() {
                    //    { "name", model.CommentName },
                    //    { "email", model.CommentEmail }
                    //});

                }
                else
                {
                    ModelState.AddModelError("", "Your comment can't be added at this time.");
                }
            }

            return View(modelContent.View(), newModel);
        }
 /// <summary>Retracts false positive from Akismet database.</summary>
 /// <param name="comment">AkismetComment object to retract.</param>
 public void SubmitHam(AkismetComment comment)
 {
     HttpPost(String.Format(SubmitHamUrl, _apiKey), CreateData(comment), CharSet);
 }
 /// <summary>Checks AkismetComment object against Akismet database.</summary>
 /// <param name="comment">AkismetComment object to check.</param>
 /// <returns>'True' if spam, 'False' if not spam.</returns>
 public bool CommentCheck(AkismetComment comment)
 {
     return Convert.ToBoolean(HttpPost(String.Format(CommentCheckUrl, _apiKey), CreateData(comment), CharSet));
 }