示例#1
0
        protected override ModelDriverResult Update(SocketEventContext model, dynamic shapeHelper, Orchard.ContentManagement.IUpdateModel updater, ModelShapeContext context)
        {
            if (model.Connector.Name != "UserToAddress")
            {
                return(null);
            }

            var prefix    = FullPrefix(context);
            var viewModel = BuildCreateModel();

            if (updater != null && updater.TryUpdateModel(viewModel, prefix, null, null) && !string.IsNullOrWhiteSpace(viewModel.PostalCode))
            {
                var address = _directoryService.CreateAddress(viewModel, updater, prefix);
                if (address == null)
                {
                    updater.AddModelError(FullPrefix(context, "PostalCode"), T("Please specify a valid postcode and address"));
                }
                else
                {
                    // Create connector
                    model.Query.Connectors.Add(address.Id, "UserToAddress", null, true);
                }
            }
            return(ModelShape("Socket_Creators_Address", shapeHelper.EditorTemplate(TemplateName: "Socket.Creators.Address", Prefix: prefix, Model: viewModel)));
        }
示例#2
0
        protected override DriverResult Editor(TaxonomyPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
        {
            TaxonomyPart existing = _taxonomyService.GetTaxonomyByName(part.Name);

            if (existing != null && existing.Record != part.Record)
            {
                updater.AddModelError("Title", T("A taxonomy with the same name already exists"));
            }

            // nothing to display for this part
            return(null);
        }
        protected override DriverResult Editor(ScriptValidationPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
        {
            var script = part.Settings.GetModel <ScriptValidationPartSettings>().Script;

            if (!String.IsNullOrWhiteSpace(script))
            {
                _csharpService.SetParameter("Services", _orchardServices);
                _csharpService.SetParameter("ContentItem", (dynamic)part.ContentItem);
                _csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
                _csharpService.SetFunction("T", (Func <string, string>)(x => T(x).Text));
                _csharpService.SetFunction("AddModelError", (Action <string>)(x => updater.AddModelError("Script", T(x))));

                _csharpService.Run(script);
            }

            return(Editor(part, shapeHelper));
        }