Copied to clipboard

Flag this post as spam?

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


  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 23, 2018 @ 03:22
    Nguyen Thi Thu Trang
    0

    I have updated the db into cmsPropertyData table,

    but when i get api on postman the result is still not updated,

    Is it because I do not refresh the UmbracoContext?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 23, 2018 @ 08:42
    Alex Skrypnyk
    0

    Hi Nguyen

    What api did you mean? Can you share the code of api?

    ContentService is working directly with database - you have to use it in API then all data will be fresh and latest

    /Alex

  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 23, 2018 @ 08:49
    Nguyen Thi Thu Trang
    0

    Firstly

    private static readonly UmbracoHelper UmbracoHelper = new UmbracoHelper(UmbracoContext.Current);

    then To get image url I use

    public static string GetMediaPickerUrl(IPublishedContent content, string imageField) { var imageUrl = string.Empty; try { if (content.HasValue(imageField)) { var mediaItem = UmbracoHelper.TypedMedia(content.GetPropertyValue but when i get api on postman the image_url is still not updated,

  • Garðar Þorsteinsson 113 posts 534 karma points
    Feb 23, 2018 @ 10:50
    Garðar Þorsteinsson
    2

    Hi,

    I would recommend you to read the common pitfalls of Umbraco.

    https://our.umbraco.org/documentation/reference/Common-Pitfalls/

    Its not recommended to use static for the UmbracoHelper.

    This practice can cause memory leaks along with inconsistent data results when using this _umbracoHelper instance.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 23, 2018 @ 10:52
    Alex Skrypnyk
    0

    Thanks Garðar, you are right, it's much better to make an extension method for Umbraco helper.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 23, 2018 @ 10:22
    Alex Skrypnyk
    0

    Hi

    By the way, how did you update cmsPropertyData table?

    You have to publish changes with this method: ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(content);

    Alex

  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 23, 2018 @ 10:59
    Nguyen Thi Thu Trang
    0

    Thanks Alex, that right.

    I want to update image_url,

    so I used sql query to update the db.

      You have no way to use ParentContetn.SetValue to update the image url, I already have imageid

Please Sign in or register to post replies

Write your reply to:

Draft