Advertisement
lukealderton

SmartBlogLibraries 2.1.0 comment controller

Apr 27th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Net.Mail;
  6. using System.Text;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using Umbraco.Web.Mvc;
  10. using umbraco.BusinessLogic;
  11. using umbraco.cms.businesslogic.web;
  12. using System.Xml;
  13.  
  14. namespace SmartBlogLibraries.Controllers
  15. {
  16. /// <summary>
  17. /// Comment form controller deals with uBlogsy comment forms.
  18. /// </summary>
  19. public class CommentFormSurfaceController : SurfaceController
  20. {
  21. /// <summary>
  22. /// Submits a SmartBlog comment to be saved in umbraco.
  23. /// </summary>
  24. [HttpPost]
  25. [Obsolete("New SmartBlog comment forms are posted via ajax, this should not be used!", false)]
  26. public ActionResult SubmitSmartBlogComment(Models.SmartBlogCommentFormModel model)
  27. {
  28. //model not valid, do not save, but return current umbraco page
  29. if (!ModelState.IsValid)
  30. {
  31. return CurrentUmbracoPage();
  32. }
  33.  
  34. // Create the comment and add then data then publish it
  35. Dictionary<string, object> properties = new Dictionary<string, object>() {
  36. {"name", model.Name},
  37. {"email", model.Email},
  38. {"website", Server.HtmlEncode(model.Website)},
  39. {"message", Server.HtmlEncode(model.Comment)}
  40. };
  41.  
  42. Helpers.Cms.CreateContentNode(Server.HtmlEncode(model.Name), "Comment", properties, CurrentPage.Id);
  43.  
  44. XmlDocument document = new XmlDocument();
  45. document.Load(AppDomain.CurrentDomain.BaseDirectory + "/config/SmartBlog.config");
  46.  
  47. if (!string.IsNullOrEmpty(document.GetElementsByTagName("moderatorCommentEmail")[0].InnerText))
  48. {
  49. StringBuilder body = new StringBuilder();
  50. body.AppendLine("This is an automated message, please do not reply.");
  51. body.AppendLine();
  52. body.AppendLine("---------------------------------------------------");
  53. body.AppendLine();
  54. body.AppendLine("Text is as follows:");
  55. body.AppendLine();
  56. body.AppendLine("Name: " + model.Name);
  57. body.AppendLine("Email: " + model.Email);
  58. body.AppendLine("Website: " + model.Website);
  59. body.AppendLine("Comment: " + model.Comment);
  60. body.AppendLine();
  61. body.AppendLine("Regards,");
  62. body.AppendLine("Support");
  63.  
  64. SmartBlogLibraries.Helpers.Mailing.SendEmail(document.GetElementsByTagName("moderatorCommentEmail")[0].InnerText,
  65. "support@"+SmartBlogLibraries.Helpers.Http.domain,
  66. "New Comment - " + System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"],
  67. body.ToString(),
  68. model.Email);
  69. }
  70.  
  71. // Add message to the page
  72. TempData.Add("SubmissionMessage", "Your comment was successfully added.");
  73.  
  74. // Redirect to current page to clear the form
  75. return RedirectToCurrentUmbracoPage();
  76.  
  77. // Redirect to specific page
  78. //return RedirectToUmbracoPage(2525);
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement