예제 #1
0
        public ViewResult Create(ElementDataViewModel model, string session)
        {
            var sessionState    = _objectStore.Get <ElementSessionState>(session);
            var contentId       = sessionState.ContentId;
            var contentType     = sessionState.ContentType;
            var describeContext = CreateDescribeContext(contentId, contentType);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, model.TypeName);
            var data            = Request.Form.ToDictionary();
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(session, describeContext.Content, element, postedElementData: data, updater: this);
            var editorResult    = _elementManager.UpdateEditor(context);
            var viewModel       = new EditElementViewModel {
                SessionKey   = session,
                Layout       = describeContext.Content.As <ILayoutAspect>(),
                EditorResult = editorResult,
                TypeName     = model.TypeName,
                DisplayText  = descriptor.DisplayText,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
            };

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();
            }
            else
            {
                viewModel.Submitted          = true;
                viewModel.ElementEditorModel = _mapper.ToEditorModel(element, describeContext);
            }
            return(View(viewModel));
        }
        public ActionResult Edit(int id, ElementDataViewModel model)
        {
            var blueprint       = _elementBlueprintService.GetBlueprint(id);
            var describeContext = DescribeElementsContext.Empty;
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName);
            var data            = ElementDataHelper.Deserialize(model.ElementData).Combine(Request.Form.ToDictionary());
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(element, elementData: data);
            var editorResult    = _elementManager.UpdateEditor(context);
            var viewModel       = new EditElementBlueprintViewModel {
                EditorResult = editorResult,
                TypeName     = model.TypeName,
                DisplayText  = descriptor.DisplayText,
                Description  = descriptor.Description,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                BaseElement  = element
            };

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();
                return(View(viewModel));
            }

            blueprint.BaseElementState = data.Serialize();
            _signals.Trigger(Signals.ElementDescriptors);
            _notifier.Information(T("That blueprint has been saved."));
            return(RedirectToAction("Index"));
        }
예제 #3
0
        protected override DriverResult Editor(ElementWrapperPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            return(ContentShape("Parts_ElementWrapper_Edit", () => {
                var describeContext = CreateDescribeContext(part);
                var descriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, part.ElementTypeName);
                var data = ElementDataHelper.Deserialize(part.ElementData).Combine(_wca.GetContext().HttpContext.Request.Form.ToDictionary());
                var dataClosure = data;
                var element = _elementManager.ActivateElement(descriptor, e => e.Data = dataClosure);
                var context = CreateEditorContext(describeContext.Content, element, data, updater, shapeHelper);
                var editorResult = (EditorResult)(updater != null ? _elementManager.UpdateEditor(context) : _elementManager.BuildEditor(context));
                var viewModel = new ElementWrapperPartViewModel {
                    Tabs = editorResult.CollectTabs().ToArray(),
                    ElementTypeName = part.ElementTypeName,
                    ElementDisplayText = element.DisplayText,
                    ElementEditorResult = editorResult,
                    ElementEditors = editorResult.Editors,
                };

                data = context.ElementData;

                if (updater != null)
                {
                    part.ElementData = data.Serialize();
                }

                return shapeHelper.EditorTemplate(TemplateName: "Parts.ElementWrapper", Model: viewModel, Prefix: Prefix);
            }));
        }
예제 #4
0
        public ViewResult Update(string session)
        {
            var sessionState    = _objectStore.Get <ElementSessionState>(session);
            var contentId       = sessionState.ContentId;
            var contentType     = sessionState.ContentType;
            var typeName        = sessionState.TypeName;
            var elementData     = ElementDataHelper.Deserialize(sessionState.ElementData);
            var describeContext = CreateDescribeContext(contentId, contentType);
            var descriptor      = _elementManager.GetElementDescriptorByTypeName(describeContext, typeName);
            var data            = elementData.Combine(ElementDataHelper.Deserialize(sessionState.ElementEditorData));
            var element         = _elementManager.ActivateElement(descriptor, e => e.Data = data);
            var context         = CreateEditorContext(session, describeContext.Content, element, elementData, this);
            var editorResult    = _elementManager.UpdateEditor(context);

            var viewModel = new EditElementViewModel {
                Layout       = describeContext.Content.As <ILayoutAspect>(),
                EditorResult = editorResult,
                TypeName     = typeName,
                DisplayText  = descriptor.DisplayText,
                ElementData  = element.Data.Serialize(),
                Tabs         = editorResult.CollectTabs().ToArray(),
                SessionKey   = session
            };

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();
            }
            else
            {
                viewModel.ElementHtml        = RenderElement(element, describeContext);
                viewModel.Submitted          = true;
                viewModel.ElementEditorModel = _mapper.ToEditorModel(element, describeContext);
            }
            return(View("Edit", viewModel));
        }