Creating DynamicContent with code

Posted by Community Admin on 04-Aug-2018 16:36

Creating DynamicContent with code

All Replies

Posted by Community Admin on 12-Mar-2012 00:00

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 ?

Posted by Community Admin on 13-Mar-2012 00:00

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?

This thread is closed