Create custom settings based on user

Topics: Customizing Orchard
Sep 23, 2011 at 8:13 AM

I have followed this thread http://www.orchardproject.net/docs/Adding-custom-settings.ashx , but it still doesn't fulfill my requirement . I will explain my project below

-I want to create a multi-shop website, that allow people to register as a shop owner and selling their items. Each shop owner will have an account with the role ShopAdmin . So i want to create a settings section for them , but it must separate with the setting of SuperAdmin. I have read the Orchard.Core.Settings and try to make the same like it , but I still don't understand how it's done.

Anyone have done the same before or have any advices ? Thanks very much

Coordinator
Sep 23, 2011 at 5:15 PM

Sounds like plain multi-tenancy.

Sep 26, 2011 at 1:50 AM

I have done creating another section for setting named ShopSettings content type , but now I have another problem. I will take the "Site" content type for example : I have created a setting part called CurrencySettings , and I want add it to the Settings section, so the code will be

Filters.Add(new ActivatingFilter<CurrencySettingsPart>("Site"));

After that, I want to create a menu for it , not inside the General page 

Filters.Add(new TemplateFilterForRecord<CurrencySettingsPartRecord>("CurrencySettings", "Parts/Currency.Setting", T("Currency").ToString()));

The code should work when the model pass into the view Currency.Setting is CurrencySettingsPartRecord , but my model need to be more complex (with some dropdownlists) , 
so I can't use the record for model . If I tried to use the record as model , I need to use something like Viewbag to store temporary data, but the Driver doesn't accept
ViewBag. Is there any solution for it?

Thanks

 

Coordinator
Sep 26, 2011 at 3:56 AM

Sure, that's what shapes are for. You just need a driver for your part, that's all.

Sep 26, 2011 at 4:58 AM

Can you explain more details , for example if you want to build a dropdownlist in the form , you need a list of items first , and in the Record we can't not have a List of items there.

Coordinator
Sep 26, 2011 at 5:04 AM

That's why I'm telling you to use a shape: it's a dynamic object, so you can put anything you want on it.

Sep 26, 2011 at 8:24 AM

Sorry but I still don't undestand , plz look at my Editor method below

 

protected override DriverResult Editor(CurrencySettingsPart part, dynamic shapeHelper)
        {
            
            var shopId = _workContext.CurrentUser.ContentItem.
                As<ShopPart>().Shop.Id;
            var currency = _shopService.GetShopSettings(shopId).As<CurrencySettingsPart>();
            var model = new CurrencySettingsViewModel(_currencyService, _workContext) {
                Currencies = _currencyService.GetCurrencies().Select(x => new ViewModelTemp() {
                    Id = x.Id,
                    Name = x.Name
                }),
                Currency = currency
            };

            return ContentShape("Parts_Currency_Setting", () => 
                shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)).OnGroup("currency");
        }

        protected override DriverResult Editor(CurrencySettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var shopId = _workContext.CurrentUser.ContentItem.
                As<ShopPart>().Shop.Id;
            var currency = _shopService.GetShopSettings(shopId).As<CurrencySettingsPart>();
            var model = new CurrencySettingsViewModel(_currencyService, _workContext)
            {
                Currencies = _currencyService.GetCurrencies().Select(x => new ViewModelTemp()
                {
                    Id = x.Id,
                    Name = x.Name
                }),
                Currency = currency
            };

            return ContentShape("Parts_Currency_Setting", () =>
            {
                if (updater != null)
                {
                    updater.TryUpdateModel(part.Record, Prefix, null, null);
                }
                return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
            })
                .OnGroup("currency");
        }
    }

 

I'm passing a view model to the Editor method above, so if I use a Record as model , how can I pass the Currencies list to it , I have read some Editor method of other projects but no clue. 

I know that shape is dynamic and can add anything into it , but I see that it only uses in Display method

Coordinator
Sep 26, 2011 at 11:13 PM

EditorTemplate is just one of the built-in shapes, and it happens to know what to do with the Model property. You do not have to use an EditorTemplate as far as I know, it's just a helper. You should be able to use any shape of your choice, including one that you invent, the same way you would in the Display method.