More in this section

Forums / Developing with Sitefinity / Creating DynamicContent with code

Creating DynamicContent with code

2 posts, 0 answered
  1. Elsane
    Elsane avatar
    30 posts
    Registered:
    06 Jan 2012
    12 Mar 2012
    Link to this post
    Hello,


    I have a Module created with the ModuleBuilder called Bill. I want to create new bill items from the front end.

    Here's my code :

           public static Bill createBill(User custommer, Product product)
            {
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                Type billType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Bill.Bill");
                DynamicContent billItem = dynamicModuleManager.CreateDataItem(billType, Guid.NewGuid(), "/ModuleBuilder");

                billItem.SetValue("Title", "Some Title" );
                billItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
                billItem.SetValue("custommerId", custommer.Id.ToString());
                billItem.SetValue("PublicationDate", DateTime.Now);
                billItem.SetValue("productId", product.Id.ToString());
                billItem.SetValue("duration", product.selectedDuration);
                billItem.SetValue("billStatus", "pending");
                billItem.SetValue("purchaseDate", null);
                billItem.SetValue("validityLimitDate", null);
                billItem.SetValue("activationDate", null);
                billItem.SetValue("price", product.price);

                billItem.Status = Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master;
                billItem.Visible = true;
                dynamicModuleManager.Lifecycle.Publish(billItem);
                dynamicModuleManager.SaveChanges();

                var test = dynamicModuleManager.GetDataItems(billType).Where(p => p.Id == billItem.Id && p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master);

                return new Bill(billItem);
            }

    My item is created in the database table "bill" but does not appear in the backend Bill page. Moreover test return no DataItem.

    Do I miss a step ?
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    13 Mar 2012
    Link to this post
    I believe the issue might have something to do with this line:

    DynamicContent billItem = dynamicModuleManager.CreateDataItem(billType, Guid.NewGuid(), "/ModuleBuilder");

    all the examples I've seen (and used) use the single parameter for the item type only, like this:

    DynamicContent billItem = dynamicModuleManager.CreateDataItem(billType);

    can you try that and see if it resolves the issue?

    if it does can you tell me if you used example code and where you found it so I can try to see what's going on?
2 posts, 0 answered