Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • shukriadams 3 posts 23 karma points
    Mar 28, 2015 @ 03:22
    shukriadams
    0

    How do I save / update / delete on server from my AngularJS editor?

    There are several tutorials online about how to make a custom editor using the new AngularJS editor system. None of them seem to explain how to do data operations on the serverside however. Or am I missing some really fundamental aspect of how Umbraco handles on the server - is it all wired up automatically?

    I have a DocumentType, let's call it StandardPage, it has a DataType property, let's call that Address. Address has some strings, Line1, Line2, etc - so it's a complex object. I have an Angular editor that's supposed to edit Address. The editor posts data to an UmbracoAuthorizedJsonController which has a Save method. So far so good.

    In my editor's .resource.js file, I have a save handler :

     save: function(data, parentId) {
    return $http.post("backoffice/MySite/Editor/Save", angular.toJson(data, parentId));
    },

    where data is some form data, and parentId is the id of the StandardPage I want to edit. Posting back works, I can retrieve the object I want to edit .... but now what? 

    In my save method, I can do 

    IContent standardPage = UmbracoContext.Application.Services.ContentService.GetById(parentId);

    This gets the StandardPage record I want to edit - how do I save the data I just sent to the server? How do I save a complex object to standardPage's Address property? How can I delete the address again? There's an UmbracoContext.Application.Services.DataTypeService, it has save and delete methods, but I don't see where or how I write to page properties with that.

    Thanks.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 28, 2015 @ 17:31
    Alex Skrypnyk
    0

    Hi Shukri Adams,

    Save / update / delete on server you have to write your own api controllers and manage your requests.

    THanks

  • shukriadams 3 posts 23 karma points
    Mar 28, 2015 @ 19:21
    shukriadams
    0

    Any examples or documentation that explains what the server-side code should look like? I'm completely new to Umbraco so I don't have much to go on.

  • shukriadams 3 posts 23 karma points
    Mar 29, 2015 @ 03:02
    shukriadams
    0

    After digging into this a bit more, I can see that it's pretty easy for me to update a custom property on a DocumentType or DataType as long as I write only string data to them.

    So my controller code looks like :

    IContent doc= UmbracoContext.Application.Services.ContentService.GetById(parentId);
    string serialized = myobject.serializeToJson();
    doc.Properties["someProperty"].Value = serialized; 
    ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(doc); 


    Is this the intented way to handle complex custom objects in Umbraco?

Please Sign in or register to post replies

Write your reply to:

Draft