Try Now
More in this section

Forums / Developing with Sitefinity / Adding child items to dynamic module parent works strange

Adding child items to dynamic module parent works strange

1 posts, 0 answered
  1. Ajai
    Ajai avatar
    15 posts
    02 Mar 2015
    18 May 2015
    Link to this post

    Hi all,

    I am working with sitefinity 7.0.

    I have created a sitefinity dynamic module Product and which has a child items of type Vendor.

    I am populating values to it by using api.I am able to add the parent product successfully.

    Suppose i am adding 2 vendors to to a parent product, but it seems that all the other vendor details created with other products are also associated with it.

    ie i have 8 vendors associated with different parent products in that dynamic module.

    So after i added to vendors to that parent product, instead of seeing 2 vedors i get 10 vendors(8+2)

     This seems to be too strange.Any idea on this?


    Given below is the code that i have used

     dynamicModuleManager = new DynamicModuleManager();
                DynamicContent productItem = dynamicModuleManager.CreateDataItem(productType);
                dynamicModuleManager.Provider.SuppressSecurityChecks = true;
                productItem.SetValue("Title", dynamicProduct.ProductName);
                productItem.SetValue("ProductId", dynamicProduct.ProductId);
                productItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
                productItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");


     var providerName = String.Empty;

                // Set the culture name for the multilingual fields
                var cultureName = "en";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);

                //DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
                //Type vendorType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Products.Vendor");
                DynamicContent vendorItem = dynamicModuleManager.CreateDataItem(vendorType);

                // This is how values for the properties are set
                vendorItem.SetString("Title", dynamicProduct.Vendor.Title, cultureName);
                vendorItem.SetString("VendorId", dynamicProduct.Vendor.VendorId, cultureName);
                vendorItem.SetString("VendorName", dynamicProduct.Vendor.VendorName, cultureName);
                vendorItem.SetValue("ProductPrice", dynamicProduct.Vendor.ProductPrice);
                vendorItem.SetValue("NumberOfClicks", 0);
                vendorItem.SetString("ProductUrl", dynamicProduct.Vendor.ProductUrl, cultureName);

                //vendorItem.SetString("UrlName", "SomeUrlName", cultureName);
                vendorItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
                //vendorItem.SetValue("PublicationDate", DateTime.Now);

                vendorItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published", new CultureInfo(cultureName));

                // Set item parent
                //Type productType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Products.Product");
                Guid parentId = this.GetParentId(dynamicModuleManager, productType);
                vendorItem.SetParent(parentId, productType.FullName);

                // You need to call SaveChanges() in order for the items to be actually persisted to data store

                // Use lifecycle so that LanguageData and other Multilingual related values are correctly created
                DynamicContent checkOutVendorItem = dynamicModuleManager.Lifecycle.CheckOut(vendorItem) as DynamicContent;






1 posts, 0 answered