1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Fluent API Example

Fluent API Example

5 posts, 0 answered
  1. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    29 Jul 2010
    Link to this post
    Can someone post some fluent api examples from the webinar for me?  Specifically the one that Ivan showed where a blog is created and then post are added to it within the same scope.  There was a piece of code that added a description to the blog after it had been created and a child post was created.. We are curious to see this code again...


    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Jul 2010
    Link to this post
    Hi Drew Greenwell,

    Below is a sample code. I believe that the webinar will be available on tv.telerik.com or/and sitefinitywatch.com so you will be able to take a look at it again.

    using Telerik.Sitefinity;
    using Telerik.Sitefinity.GenericContent.Model;
    ..
         ...
                
        var BlogId = Guid.Empty;
        App.WorkWith()
            .Blog()
            .CreateNew()
            .Do(b =>
                {
                    b.Title = "NewBlog";
                    b.Description = "My 4.0 Blog";
                    BlogId = b.Id;
                })
            .SaveChanges();
    }


    You can retrieve the blog like this

    myBlog = App.WorkWith().Blogs().Where(b => b.Title == "NewBlog").Get().First();

    For creating content items you will be able to use App.WorkWith().Blog(NewBlog) .BlogPost().CreateNew().Do( b  => { b.Owner = myBlog.Id}) and finally commit the changes.

    We will provide more documentation and samples with the BETA.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    29 Jul 2010
    Link to this post
    Thanks for the response Ivan. I was wondering about the code where you created a blog then created posts for it all in one statement..

    it was something like

    App.WorksWith()
        .Blog()
        .CreateNew()
        .Do(b=> {
            b.Title = "A new Blog";
            })          
                .BlogPost().CreateNew()
                .Do(bp => {bp.Title = "A new Blog Post";})
                .Done()
         //b shouldnt exist here so I think Im missing a step you took to reaccess the blog object you created
        .Do(b.Description = "Oops forgot to add a description")
        .SaveChanges();


    Thanks again for the response and thanks for the outstanding effort you guys are putting in
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    30 Jul 2010
    Link to this post
    Hi Drew Greenwell,

    Yes, some minor corrections are needed:

    App.WorksWith()
        .Blog()
        .CreateNew()
        .Do(b => {
            b.Title = "A new Blog";
            })         
                .BlogPost()
                  .CreateNew()
                  .Do(bp => {bp.Title = "A new Blog Post";})
                  .Done()
        .Do( b => b.Description = "Oops forgot to add a description")
        .SaveChanges();

    Check the highlighted. Everytime you use Do(), you are able to access the content item's properties behind the current facade (in the highlighted case, Blog() facade.

    Sincerely yours,
    Georgi
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    30 Jul 2010
    Link to this post
    I figured that was it, Thanks!
5 posts, 0 answered