Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Net.Mail;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- using Umbraco.Web.Mvc;
- using umbraco.BusinessLogic;
- using umbraco.cms.businesslogic.web;
- using System.Xml;
- namespace SmartBlogLibraries.Controllers
- {
- /// <summary>
- /// Comment form controller deals with uBlogsy comment forms.
- /// </summary>
- public class CommentFormSurfaceController : SurfaceController
- {
- /// <summary>
- /// Submits a SmartBlog comment to be saved in umbraco.
- /// </summary>
- [HttpPost]
- [Obsolete("New SmartBlog comment forms are posted via ajax, this should not be used!", false)]
- public ActionResult SubmitSmartBlogComment(Models.SmartBlogCommentFormModel model)
- {
- //model not valid, do not save, but return current umbraco page
- if (!ModelState.IsValid)
- {
- return CurrentUmbracoPage();
- }
- // Create the comment and add then data then publish it
- Dictionary<string, object> properties = new Dictionary<string, object>() {
- {"name", model.Name},
- {"email", model.Email},
- {"website", Server.HtmlEncode(model.Website)},
- {"message", Server.HtmlEncode(model.Comment)}
- };
- Helpers.Cms.CreateContentNode(Server.HtmlEncode(model.Name), "Comment", properties, CurrentPage.Id);
- XmlDocument document = new XmlDocument();
- document.Load(AppDomain.CurrentDomain.BaseDirectory + "/config/SmartBlog.config");
- if (!string.IsNullOrEmpty(document.GetElementsByTagName("moderatorCommentEmail")[0].InnerText))
- {
- StringBuilder body = new StringBuilder();
- body.AppendLine("This is an automated message, please do not reply.");
- body.AppendLine();
- body.AppendLine("---------------------------------------------------");
- body.AppendLine();
- body.AppendLine("Text is as follows:");
- body.AppendLine();
- body.AppendLine("Name: " + model.Name);
- body.AppendLine("Email: " + model.Email);
- body.AppendLine("Website: " + model.Website);
- body.AppendLine("Comment: " + model.Comment);
- body.AppendLine();
- body.AppendLine("Regards,");
- body.AppendLine("Support");
- SmartBlogLibraries.Helpers.Mailing.SendEmail(document.GetElementsByTagName("moderatorCommentEmail")[0].InnerText,
- "support@"+SmartBlogLibraries.Helpers.Http.domain,
- "New Comment - " + System.Web.HttpContext.Current.Request.ServerVariables["HTTP_HOST"],
- body.ToString(),
- model.Email);
- }
- // Add message to the page
- TempData.Add("SubmissionMessage", "Your comment was successfully added.");
- // Redirect to current page to clear the form
- return RedirectToCurrentUmbracoPage();
- // Redirect to specific page
- //return RedirectToUmbracoPage(2525);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement