Guest User

Umbraco

a guest
May 14th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. public partial class CreateContent : Window
  2. {
  3.         public IContentService contentService { get; set; }
  4.         public IContentTypeService contentTypeService { get; set; }
  5.  
  6.         public CreateContent(IContentService contentService, IContentTypeService contentTypeService)
  7.         {
  8.             InitializeComponent();
  9.             this.contentService = contentService;
  10.             this.contentTypeService = contentTypeService;
  11.             PrintContentTypes();
  12.         }
  13.  
  14.         public void PrintContentTypes()
  15.         {
  16.             List<string> test = new List<string>();
  17.             //We find all ContentTypes so we can show a nice list of everything that is available
  18.             var contentTypes = contentTypeService.GetAllContentTypes();
  19.             foreach (var item in contentTypes)
  20.             {
  21.                 test.Add(item.Alias);
  22.             }
  23.             Alias.ItemsSource = test;
  24.         }
  25.  
  26.         private void bttnSave_Click(object sender, RoutedEventArgs e)
  27.         {
  28.             var contentTypeAlias = Alias.Text;
  29.             var parentId = int.Parse(parentID.Text);
  30.             var contentname = contentName.Text;
  31.  
  32.             CreateNewContent(contentTypeAlias, parentId, contentname);
  33.         }
  34.  
  35.         private void CreateNewContent(string contentTypeAlias, int parentID, string contentName)
  36.         {
  37.             var contentObject = this.contentService.CreateContent(contentName, parentID, contentTypeAlias);
  38.             this.contentService.SaveAndPublishWithStatus(contentObject);
  39.             MessageBox.Show("Content saved!");
  40.             //Application.Current.Shutdown();
  41.         }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment