Created
February 3, 2013 17:45
-
-
Save mikeedwards83/4702772 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CommentController : SitecoreController | |
| { | |
| ISitecoreContext _context; | |
| ISitecoreService _master; | |
| /// <summary> | |
| /// This constructor can be used with dependency injection or unit testing | |
| /// </summary> | |
| /// <param name="context"></param> | |
| public CommentController(ISitecoreContext context, ISitecoreService master) | |
| { | |
| _context = context; | |
| _master = master; | |
| } | |
| [HttpGet] | |
| public override ActionResult Index() | |
| { | |
| var model = _context.CreateClass<CommentPage>(false, false, PageContext.Current.Item); | |
| return View(model); | |
| } | |
| [HttpPost] | |
| public ActionResult Index(Comment comment) | |
| { | |
| var webModel = _context.CreateClass<CommentPage>(false, false, PageContext.Current.Item); | |
| if (ModelState.IsValid && comment != null) | |
| { | |
| var masterModel = _master.GetItem<CommentPage>(webModel.Id); | |
| if (masterModel.CommentFolder == null) | |
| { | |
| CommentFolder folder = new CommentFolder(); | |
| folder.Name = "Comments"; | |
| using (new SecurityDisabler()) | |
| { | |
| _context.Create(masterModel, folder); | |
| } | |
| masterModel.CommentFolder = folder; | |
| } | |
| using (new SecurityDisabler()) | |
| { | |
| comment.Name = DateTime.Now.ToString("yyyyMMddhhmmss"); | |
| //create the comment in the master database | |
| _master.Create(masterModel.CommentFolder, comment); | |
| webModel.CommentAdded = true; | |
| } | |
| } | |
| return View(webModel); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment