Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using MvcCourse.Core.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Web.Mvc;
  8. using Umbraco.Web.Mvc;
  9. using Umbraco.Web.PublishedContentModels;
  10.  
  11. namespace MvcCourse.Core.Controllers
  12. {
  13. public class DocumentationFormController : SurfaceController
  14. {
  15.  
  16. [ChildActionOnly]
  17. public ActionResult Render(Documentation model)
  18. {
  19. var documentationFormModel = new DocumentationFormModel()
  20. {
  21. Name = model.Name,
  22. BodyText = model.BodyText.ToString()
  23. };
  24.  
  25. return PartialView("~/Views/Partials/DocumentationForm.cshtml", documentationFormModel);
  26. }
  27. [HttpPost]
  28. public ActionResult Submit(DocumentationFormModel model)
  29. {
  30.  
  31. if (ModelState.IsValid == false)
  32. {
  33. return CurrentUmbracoPage();
  34. }
  35. var currentPageId = CurrentPage.Id;
  36.  
  37. var contentService = Services.ConsentService;
  38.  
  39. var content = contentService.GetById(currentPageId);
  40.  
  41. content.Name = model.Name;
  42.  
  43. var bodyTextProperty = Documentation.GetModelPropertyType(d => d.BodyText);
  44. content.SetValue(bodyTextProperty.PropertyTypeAlias, model.BodyText);
  45.  
  46. contentService.SaveAndPublishWithStatus(content);
  47.  
  48. return RedirectToCurrentUmbracoPage();
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement