Esempio n. 1
0
        public ConvertResponse Convert(RenderContext context, JObject ConvertResult)
        {
            var page = context.GetItem <Page>();

            if (page == null || string.IsNullOrEmpty(page.Body) || page.Dom == null)
            {
                return(null);
            }
            string convertname = Lib.Helper.JsonHelper.GetString(ConvertResult, "name");
            string converttype = Lib.Helper.JsonHelper.GetString(ConvertResult, "ConvertToType");

            var name = ConvertManager.GetUniqueName(context, converttype, convertname);

            Sites.Contents.Models.HtmlBlock block = new Contents.Models.HtmlBlock();
            block.Name = name;
            string convertvalue = Lib.Helper.JsonHelper.GetString(ConvertResult, "HtmlBody");
            var    culture      = string.IsNullOrEmpty(context.Culture) ? string.Empty : context.Culture;

            block.SetValue(culture, convertvalue);

            context.WebSite.SiteDb().HtmlBlocks.AddOrUpdate(block);

            return(new ConvertResponse()
            {
                IsSuccess = true,
                ComponentNameOrId = block.Name,
                Tag = "<htmlblock id='" + block.Name.ToString() + "'></htmlblock>"
            });
        }
Esempio n. 2
0
 public void Execute(RenderContext context, List <IInlineModel> updatelist)
 {
     foreach (var item in updatelist)
     {
         var blockupdate = item as Model.HtmlblockModel;
         if (blockupdate == null)
         {
             continue;
         }
         if (blockupdate.Action == ActionType.Add)
         {
             Kooboo.Sites.Contents.Models.HtmlBlock block = new Contents.Models.HtmlBlock();
             block.Name = blockupdate.NameOrId;
             block.SetValue(context.Culture, blockupdate.Value);
             context.WebSite.SiteDb().HtmlBlocks.AddOrUpdate(block, context.User.Id);
         }
         else if (blockupdate.Action == ActionType.Update)
         {
             var block = context.WebSite.SiteDb().HtmlBlocks.GetByNameOrId(blockupdate.NameOrId);
             if (block != null)
             {
                 block.SetValue(context.Culture, blockupdate.Value);
                 context.WebSite.SiteDb().HtmlBlocks.AddOrUpdate(block, context.User.Id);
             }
         }
         else if (blockupdate.Action == ActionType.Delete)
         {
             var block = context.WebSite.SiteDb().HtmlBlocks.GetByNameOrId(blockupdate.NameOrId);
             if (block != null)
             {
                 context.WebSite.SiteDb().HtmlBlocks.Delete(block.Id, context.User.Id);
             }
         }
     }
 }