public Guid AddPost(string title, string description, string publicationStatus)
        {
            IPage page = PageManager.GetPageById(PageId, true);

            if (page != null)
            {
                var entry = DataFacade.BuildNew <Entries>();
                entry.Date              = DateTime.Now;
                entry.Title             = title;
                entry.Content           = RelativeMediaUrl(MarkupTransformationServices.TidyHtml(description).Output.Root);
                entry.PublicationStatus = publicationStatus;
                entry.Tags              = string.Empty;
                entry.Teaser            = string.Empty;
                entry.Author            = Author.Id;
                PageFolderFacade.AssignFolderDataSpecificValues(entry, page);
                entry = DataFacade.AddNew(entry);

                if (publicationStatus == GenericPublishProcessController.Published)
                {
                    entry.PublicationStatus = publicationStatus;
                    DataFacade.Update(entry);
                }
                return(entry.Id);
            }
            return(Guid.Empty);
        }
示例#2
0
        private void enterDataCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var dataTypeDescriptor = GetBinding <DataTypeDescriptor>("DataTypeDescriptor");

            var type = TypeManager.GetType(dataTypeDescriptor.TypeManagerTypeName);

            Guid pageId = GetBinding <Guid>(BindingNames.PageId);

            var helper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor, true, EntityToken)
            {
                LayoutIconHandle = "associated-data-add"
            };

            var generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor);

            helper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames);

            IData newData;

            if (!BindingExist("NewData"))
            {
                newData = DataFacade.BuildNew(type);

                PageFolderFacade.AssignFolderDataSpecificValues(newData, pageId);

                var publishControlled = newData as IPublishControlled;
                if (publishControlled != null)
                {
                    publishControlled.PublicationStatus = GenericPublishProcessController.Draft;
                }

                var localizedData = newData as ILocalizedControlled;
                if (localizedData != null)
                {
                    var cultureInfo = UserSettings.ActiveLocaleCultureInfo ?? DataLocalizationFacade.DefaultLocalizationCulture;
                    localizedData.SourceCultureName = cultureInfo.Name;
                }

                Bindings.Add("NewData", newData);

                helper.UpdateWithNewBindings(Bindings);
                helper.ObjectToBindings(newData, Bindings);
            }
            else
            {
                newData = GetBinding <IData>("NewData");
            }

            DeliverFormData(
                type.Name,
                StandardUiContainerTypes.Document,
                helper.GetForm(),
                Bindings,
                helper.GetBindingsValidationRules(newData)
                );
        }
示例#3
0
        public static void InsertForm(Control control, ParameterList parameters)
        {
            Page currentPageHandler = HttpContext.Current.Handler as Page;


            if (currentPageHandler == null)
            {
                throw new InvalidOperationException("The Current HttpContext Handler must be a System.Web.Ui.Page");
            }

            Type dataType = null;
            DataTypeDescriptor dataTypeDescriptor = null;

            string dataTypeName = parameters.GetParameter <string>("DataType");

            dataType           = TypeManager.GetType(dataTypeName);
            dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(dataType);

            IFormChannelIdentifier channelIdentifier = FormsRendererChannel.Identifier;

            formHelper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor);

            newData = DataFacade.BuildNew(dataType);
            GeneratedTypesHelper.SetNewIdFieldValue(newData);

            //Hide not editable fields, fox example - PageId
            GeneratedTypesHelper generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor);

            formHelper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames);


            //If is Page Datatype
            if (PageFolderFacade.GetAllFolderTypes().Contains(dataType))
            {
                IPage currentPage = PageRenderer.CurrentPage;

                if (currentPage.GetDefinedFolderTypes().Contains(dataType) == false)
                {
                    currentPage.AddFolderDefinition(dataType.GetImmutableTypeId());
                }
                PageFolderFacade.AssignFolderDataSpecificValues(newData, currentPage);
            }

            _compiler = new FormTreeCompiler();

            //bindings = formHelper.GetBindings(newData);
            bindings = new Dictionary <string, object>();
            formHelper.UpdateWithNewBindings(bindings);
            formHelper.ObjectToBindings(newData, bindings);


            using (XmlReader reader = XDocument.Parse(formHelper.GetForm()).CreateReader())
            {
                try
                {
                    _compiler.Compile(reader, channelIdentifier, bindings, formHelper.GetBindingsValidationRules(newData));

                    #region ClientValidationRules
                    clientValidationRules = new Dictionary <string, List <ClientValidationRule> >();
                    foreach (var item in _compiler.GetField <object>("_context").GetProperty <IEnumerable>("Rebindings"))
                    {
                        var SourceProducer = item.GetProperty <object>("SourceProducer");
                        var uiControl      = SourceProducer as IWebUiControl;
                        if (uiControl != null)
                        {
                            clientValidationRules[uiControl.UiControlID] = uiControl.ClientValidationRules;
                        }
                    }
                    #endregion
                }
                catch (ConfigurationErrorsException e)
                {
                    if (e.Message.Contains("Failed to load the configuration for IUiControlFactory"))
                    {
                        throw new ConfigurationErrorsException("Composite.Forms.Renderer does not support widget. " + e.Message);
                    }
                    else
                    {
                        throw new ConfigurationErrorsException(e.Message);
                    }
                }
            }
            webUiControl = (IWebUiControl)_compiler.UiControl;

            Control form = webUiControl.BuildWebControl();
            control.Controls.Add(form);

            /*if (currentPageHandler.IsPostBack)
             *  try
             *  {
             *      compiler.SaveControlProperties();
             *  }
             *  catch { }*/

            if (!currentPageHandler.IsPostBack)
            {
                webUiControl.InitializeViewState();
            }



            return;
        }
示例#4
0
        public static IEnumerable <XElement> SaveComment(string name, string email, string commentTitle, string commentText, string Captcha)
        {
            var currentPageId = SitemapNavigator.CurrentPageId;

            yield return(new XElement("SubmittedData",
                                      new XAttribute("Fieldname", "Name"),
                                      new XAttribute("Value", name)));

            yield return(new XElement("SubmittedData",
                                      new XAttribute("Fieldname", "Email"),
                                      new XAttribute("Value", email)));

            yield return(new XElement("SubmittedData",
                                      new XAttribute("Fieldname", "CommentTitle"),
                                      new XAttribute("Value", commentTitle)));

            yield return(new XElement("SubmittedData",
                                      new XAttribute("Fieldname", "CommentText"),
                                      new XAttribute("Value", commentText)));

            yield return(new XElement("SubmittedData",
                                      new XAttribute("Fieldname", "Captcha"),
                                      new XAttribute("Value", Captcha)));

            // Input error ?
            if (Captcha != "true" || string.IsNullOrEmpty(name) || !Validate(RegExpLib.Email, email, true) || string.IsNullOrEmpty(commentTitle) || string.IsNullOrEmpty(commentText))
            {
                var errorText = new Hashtable();

                if (Captcha != "true")
                {
                    errorText.Add("Captcha", "Incorrect Captcha value");
                }
                if (string.IsNullOrEmpty(name))
                {
                    errorText.Add("Name", "Incorrect Name value");
                }
                if (!Validate(RegExpLib.Email, email, true))
                {
                    errorText.Add("Email", "Incorrect E-mail value");
                }
                if (string.IsNullOrEmpty(commentTitle))
                {
                    errorText.Add("Title", "Incorrect Title value");
                }
                if (string.IsNullOrEmpty(commentText))
                {
                    errorText.Add("Comment", "Incorrect Comment value");
                }

                foreach (string key in errorText.Keys)
                {
                    yield return(new XElement("Error",
                                              new XAttribute("Fieldname", key),
                                              new XAttribute("ErrorDescription", errorText[key].ToString())));
                }
            }
            else
            {
                using (DataConnection conn = new DataConnection())
                {
                    var currentPage = conn.Get <IPage>().Where(p => p.Id == currentPageId).SingleOrDefault();

                    if (!currentPage.GetDefinedFolderTypes().Contains(typeof(Item)))
                    {
                        currentPage.AddFolderDefinition(typeof(Item).GetImmutableTypeId());
                    }

                    //add data
                    var commentItem = conn.CreateNew <Item>();

                    commentItem.Name    = name;
                    commentItem.Email   = email;
                    commentItem.Title   = commentTitle;
                    commentItem.Date    = DateTime.Now;
                    commentItem.Comment = commentText;

                    PageFolderFacade.AssignFolderDataSpecificValues(commentItem, currentPage);
                    conn.Add <Item>(commentItem);

                    // Redirect to view newly added comment
                    string pageUrl;
                    var    found = PageStructureInfo.TryGetPageUrl(currentPageId, out pageUrl);

                    if (found)
                    {
                        PrepareMail(currentPageId, pageUrl, name, email, commentTitle, commentText, DateTime.Now.ToString());
                        HttpContext.Current.Response.Redirect(pageUrl, false);
                    }
                }
            }
        }
        private void initializeCodeActivity_BuildNewData_ExecuteCode(object sender, EventArgs e)
        {
            Initialize();

            this.FormsHelper.UpdateWithNewBindings(this.Bindings);

            IData newData = DataFacade.BuildNew(InterfaceType);

            if (PageFolderFacade.GetAllFolderTypes().Contains(InterfaceType))
            {
                Dictionary <string, string> piggybag = PiggybagSerializer.Deserialize(this.ExtraPayload);
                var   piggybagDataFinder             = new PiggybagDataFinder(piggybag, this.EntityToken);
                IPage page = (IPage)piggybagDataFinder.TryGetData(typeof(IPage));
                if (page != null)
                {
                    PageFolderFacade.AssignFolderDataSpecificValues(newData, page);
                }
            }

            var publishControlled = newData as IPublishControlled;

            if (publishControlled != null)
            {
                publishControlled.PublicationStatus = GenericPublishProcessController.Draft;
            }


            var values            = new Dictionary <string, string>();
            var castedEntityToken = this.EntityToken as TreeDataFieldGroupingElementEntityToken;

            if (castedEntityToken != null)
            {
                Tree tree     = TreeFacade.GetTree(castedEntityToken.Source);
                var  treeNode = (DataFolderElementsTreeNode)tree.GetTreeNode(castedEntityToken.TreeNodeId);

                if (treeNode.Range == null && !treeNode.FirstLetterOnly)
                {
                    foreach (var kvp in castedEntityToken.DeserializedGroupingValues)
                    {
                        values.Add(kvp.Key, ValueTypeConverter.Convert <string>(kvp.Value));
                    }
                }
            }

            var props = InterfaceType.GetPropertiesRecursively().ToDictionary(prop => prop.Name);

            foreach (var kvp in this.DataPayload)
            {
                // Filtering payload data which is not default field values
                if (props.ContainsKey(kvp.Key))
                {
                    values[kvp.Key] = StringConversionServices.DeserializeValueString(kvp.Value);
                }
            }

            newData.SetValues(values);



            this.FormsHelper.ObjectToBindings(newData, this.Bindings);

            GeneratedTypesHelper.SetNewIdFieldValue(newData);

            this.Bindings.Add("NewData", newData);
        }