Copied to clipboard

Flag this post as spam?

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


  • Kim Løwert 130 posts 116 karma points
    Mar 22, 2011 @ 20:38
    Kim Løwert
    0

    Update records in Data Source with Contour programmatically

    Hi everybody,

    I am using contour to hook up to a data source creating records in a table (not contour). But now I would like to manipulate the records in my own table using the Contour form I also use to create the records.

    I can see that it is possible to edit Contours own records i from the backend, so I tend to think that it is possible to render the Contour form programmatically with a given record and submit it programmatically, but can anybody help me with how it is done or give me some hints?

    Thanks a lot in advance

    Kim :)

     

  • Harald Ulriksen 207 posts 249 karma points
    Mar 22, 2011 @ 21:52
    Harald Ulriksen
    0

    Hi Kim,

    I suggest you have a look at the rest contour package http://our.umbraco.org/projects/website-utilities/cultiv-restcontour.

    The base extensions should provide you with the api calls needed.

    One note though, not sure if it has been tested with an external datasource.

  • Kim Løwert 130 posts 116 karma points
    Mar 22, 2011 @ 22:33
    Kim Løwert
    0

    Hi Harald

    Thanks for the link. I think it is very helpful, but do you know where I can find the code, as I seem to only be able to download a package with compiled code?

    Thanks a lot in advance once again :)

    Kim

  • Harald Ulriksen 207 posts 249 karma points
    Mar 23, 2011 @ 07:24
    Harald Ulriksen
    0

    Uh, crap. I thougt it came with code.

    Here's some code I have for importing csv data.

    Hope this helps,
    Harald

     

    FormStorage formStorage = new FormStorage();
    Form = formStorage.GetForm(formId);

    using (RecordService recordService = new RecordService(Form))
    {
    recordService.Open();

    Record record = recordService.Record;
    record.IP = IpAddress;
    record.UmbracoPageId = PageId;

    recordStorage.InsertRecord(record, Form);


    foreach (Field field in recordService.Form.AllFields)
    {

    //create empty field
    var recordField = new RecordField()
    {
    Field = field,
    Key = Guid.NewGuid(),
    Record = record.Id,
    Values = new List<object>()
    };


    if (FieldMappings.ContainsKey(field.Id))
    {
    if (field.PreValueSource.Type != null)
    {
    recordField.Values.Add(prevalues.Where(p => p.Key.Key == field.Id).
    Select(p => p.Value.Where(pv => pv.Value == csvData.Values[p.Key.Value]).First()).First().Id.ToString());
    }
    else
    recordField.Values.Add(csvData.Values[FieldMappings[field.Id]]);
    }

    var recordFieldStorage = new RecordFieldStorage();
    recordFieldStorage.InsertRecordField(recordField);
    record.RecordFields.Add(recordField.Key, recordField);


    }
    recordService.Submit();
    //recordService
    result.RecordId = record.Id;
    }
  • Comment author was deleted

    Mar 23, 2011 @ 09:23

    Hey Kim,

    Contour doesn't store any relation between the internal record and the record in the datasource, so making the edit work with a datasource won't be easy (if even possible)

  • Comment author was deleted

    Mar 23, 2011 @ 09:25

    First step would be to store a relation between the datasource and the internal record once you have that you should be able to perform an update on the datasource

  • Kim Løwert 130 posts 116 karma points
    Mar 23, 2011 @ 10:14
    Kim Løwert
    0

    Hi Guys

    Thanks a lot for your swift answers. They are very helpful :) I'lll experiment some more to see if I can make it work, and post my findings if successful. @Tim, is there a way to load the editform dynamically with my own custom data? And is there a submit event that I can subscribe to? If not would that be something that would make sense to add to Contour in the future?

    Once again, thanks a lot for your answers :)

    Kim

Please Sign in or register to post replies

Write your reply to:

Draft