Creating albums: native vs fluent API

Posted by Community Admin on 04-Aug-2018 08:04

Creating albums: native vs fluent API

All Replies

Posted by Community Admin on 31-Jul-2013 00:00

Hi all,

I am new to Sitefinity (this is actually my first post) and I have been struggling a bit with creating an album/library via the API. When I try to create an album via the native API as described in the documentation, the album is visible in the back-office but opening the album does not work as expected: the contents of a different album are shown, and the web URL does not contain the album URL name. Below is a sample of the code I'm using (pretty much the same as provided in the docs)

public Album CreateAlbumIfNotExists(string albumTitle)
    Album album = _libManager.GetAlbums()
        .FirstOrDefault(a => a.Title == albumTitle);
 
    if (album == null)
    
        album = _libManager.CreateAlbum();
 
        album.Title = albumTitle;
        album.DateCreated = DateTime.UtcNow;
        album.LastModified = DateTime.UtcNow;
        album.UrlName = Regex.Replace(albumTitle.ToLower(), _friendlyUrlRegex, "-");
 
        _libManager.SaveChanges();
    
 
    return album;

If I use the fluent API however, everything works as expected. Am I missing something in the above snippet perhaps? Using Sitefinity 6.1

Posted by Community Admin on 31-Jul-2013 00:00

I would suggest if you can debug the code using Visual Studio to see when it is creating the Album if the UrlName property is being set properly.  Check also you are intending to use Album.Title or Album.Name and the case of albumTitle string matches the Title or Name being returned.

Posted by Community Admin on 01-Aug-2013 00:00

Hi Jonathan,

Thanks for your reply.
While debugging I can see the UrlName being set properly, and in a second call the album is retrieved correctly by its title, and the UrlName property is still correct.

Still not sure what I'm missing. I might have to resort to the fluent API but for this I will need to update all of the interfaces using GUID's instead of Album/Image/IFolder objects.

Posted by Community Admin on 02-Aug-2013 00:00

Telerik support helped me with this issue, and it seems the documentation is missing the following statement, which is to be added right before the call to SaveChanges():

_libManager.RecompileItemUrls(album);

That does the trick!

Posted by Community Admin on 02-Aug-2013 00:00

Hello,

I am glad to hear that the problem has been resolved using the code we have sent you. Thank you for sharing it with the community.

Regards,
Stefani Tacheva
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed