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

workflow

5 posts, 0 answered
  1. Brian Crosby
    Brian Crosby avatar
    29 posts
    Registered:
    02 Jan 2006
    02 Sep 2011
    Link to this post
    Can you please provide me some code for changing a product in the products sample and checking it in and out using C#?

    I want to query only published products

    I want to check out a product and edit it and then check it in

    I want to publish a product

    Cheers!
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    02 Sep 2011
    Link to this post
    Hi Brian,

    You can take a look in the ProductsModule sample.

    To query for published products:

    var manager = ProductsManager.GetManager();
    var products = manager.GetProducts().Where(x => x.Status == ContentLifecycleStatus.Live).ToList();

    You could use the Fluent API I guess to get a product and checkout, do the changes and publish it again. But I'm not sure actually.

    Regards,
    Daniel
  3. Brian Crosby
    Brian Crosby avatar
    29 posts
    Registered:
    02 Jan 2006
    05 Sep 2011
    Link to this post
    Thank you Daniel for your response. 

    Can someone at Telerik please comment on this. I really need to find out how to properly check in and out and publish custom module data like products using C#.
  4. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    07 Sep 2011
    Link to this post
    Hello Brian Crosby,

    Like Daniel properly pointed out, you'll need to work with Productsmanager. ProductsManager inherits from ContentManagerBase, so basically what you have for a news item:
    NewsManager manager = NewsManager.GetManager();
        NewsItem item = manager.GetNewsItems()
                            .Where(t => t.Title == newsTitle)
                            .Where(t => t.Status == ContentLifecycleStatus.Live)
                            .Single();
     
        item = manager.GetMaster(item);    // make sure we are working with master
        NewsItem temp = manager.CheckOut(item); // work on a temp
        //
        temp.Content = newContent;
        //
        item = manager.CheckIn(temp);
        manager.RecompileItemUrls<NewsItem>(item);
        manager.Publish(item);
        manager.SaveChanges();
    would be identical when calling ProductsManager.GetManager();

    Greetings,
    Boyan Barnev
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    07 Sep 2011
    Link to this post
    Hello Brian Crosby,

    Just a quick follow-up, please find below a sample code for achieveing the same functionality with a products item:
    ProductsManager manager = ProductsManager.GetManager();
               ProductItem item = manager.GetProducts()
                                    .Where(t => t.Title == "title")
                                    .Where(t => t.Status == ContentLifecycleStatus.Live)
                                    .Single();
     
               item = manager.Lifecycle.GetMaster(item) as ProductItem; // make sure we are working with master
               var temp = manager.Lifecycle.CheckOut(item); // work on a temp
                
                //
                item = manager.Lifecycle.CheckIn(temp) as ProductItem;
                manager.RecompileItemUrls<ProductItem>(item);
                manager.Lifecycle.Publish(item);
                manager.SaveChanges();


    Best wishes,
    Boyan Barnev
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

5 posts, 0 answered