Esempio n. 1
0
        /// <summary>
        /// Add data and return the folder id.
        /// </summary>
        /// <param name="SiteDb"></param>
        /// <param name="TypeAndFolderName"></param>
        /// <param name="JsonData"></param>
        /// <returns></returns>
        public static DataAddResponse AddData(SiteDb SiteDb, string TypeAndFolderName, Object JsonData)
        {
            var Fields = ConvertToDataFields(JsonData);

            string ContentTypeName   = GetContentTypeName(SiteDb, TypeAndFolderName);
            string ContentFolderName = GetContentFolderName(SiteDb, TypeAndFolderName);

            var contenttype = GetContentType(ContentTypeName, Fields);

            SiteDb.ContentTypes.AddOrUpdate(contenttype);

            var contentfolder = new ContentFolder();

            contentfolder.Name          = ContentFolderName;
            contentfolder.ContentTypeId = contenttype.Id;
            SiteDb.ContentFolders.AddOrUpdate(contentfolder);

            AddValue(SiteDb, contenttype.Id, contentfolder.Id, Fields);

            DataAddResponse response = new DataAddResponse();

            response.contentFolder = contentfolder;

            foreach (var item in Fields)
            {
                if (item.ControlType == ControlTypes.DateTime)
                {
                    var datefield = new DateField();
                    datefield.Name   = item.Name;
                    datefield.Format = Lib.Helper.DateTimeHelper.ParseDateFormat(item.Values);
                    response.DateList.Add(datefield);
                }
            }

            return(response);
        }
Esempio n. 2
0
        public string UpdateViewTemplate(string template, DataAddResponse dataResponse)
        {
            if (dataResponse == null || dataResponse.DateList == null || !dataResponse.DateList.Any())
            {
                return(template);
            }

            List <SourceUpdate> sourceUpdate = new List <SourceUpdate>();

            var doc = Kooboo.Dom.DomParser.CreateDom(template);
            var els = GetPossibleEls(doc);

            foreach (var el in els)
            {
                Dictionary <string, string> dict = new Dictionary <string, string>();
                foreach (var att in el.attributes)
                {
                    dict.Add(att.name, att.value);
                }

                Dictionary <string, string> updates = new Dictionary <string, string>();

                foreach (var at in dict)
                {
                    if (at.Key.ToLower() == "k-content" || at.Key.ToLower() == "k-replace")
                    {
                        var value = at.Value;
                        foreach (var date in dataResponse.DateList)
                        {
                            if (value == date.Name || value.EndsWith("." + date.Name))
                            {
                                var newvalue = "DateFormat(" + at.Value + ", '" + date.Format + "')";
                                updates.Add(at.Key, newvalue);
                            }
                        }
                    }
                }


                if (updates.Count() > 0)
                {
                    foreach (var item in updates)
                    {
                        dict[item.Key] = item.Value;
                    }

                    SourceUpdate supdate = new SourceUpdate();
                    supdate.StartIndex = el.location.openTokenStartIndex;
                    supdate.EndIndex   = el.location.openTokenEndIndex;

                    string newopentag = Kooboo.Sites.Service.DomService.GenerateOpenTag(dict, el.tagName);
                    supdate.NewValue = newopentag;

                    sourceUpdate.Add(supdate);
                }
            }

            if (sourceUpdate.Any())
            {
                return(Kooboo.Sites.Service.DomService.UpdateSource(template, sourceUpdate));
            }
            else
            {
                return(template);
            }
        }