Пример #1
0
        public static Stream GetInventioPageStream(string path)
        {
            Stream ret = null;

            InventioPage page = PageWorker.SelectByPath(path, PageWorker.RepositoryWebConfig);

            if (page != null)
            {
                InventioLayout layout = LayoutWorker.SelectById(page.IdLayout, LayoutWorker.RepositoryWebConfig);
                if (layout != null)
                {
                    string raw    = System.Text.Encoding.UTF8.GetString(layout.Body);
                    string parsed = string.Empty;

                    // BEGIN RazorEngine Template // TODO igual hay que meterlo en global asax
                    var config = new RazorEngine.Configuration.TemplateServiceConfiguration
                    {
                        //BaseTemplateType = typeof(InventioTemplateBase<>)
                        BaseTemplateType = typeof(InventioTemplateBase <>),
                        Resolver         = new InventioTemplateResolver()
                    };

                    using (var service = new TemplateService(config))
                    {
                        RazorEngine.Razor.SetTemplateService(service);
                        parsed = Razor.Parse(raw);
                    }
                    // END RazorEngine

                    ret = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parsed), false);
                }
            }

            return(ret);
        }
Пример #2
0
 public static void Remove(string path, IPageRepository repository)
 {
     if (!string.IsNullOrWhiteSpace(path))
     {
         InventioPage selected = repository.SelectByPath(path.Replace("~", string.Empty));
         if (selected != null)
         {
             repository.Delete(selected.Id);
         }
     }
 }
Пример #3
0
        //public static Inventio SelectById(int id, ILayoutRepository Repository)
        //{
        //    return Repository.SelectById(id);
        //}

        //public static List<InventioLayout> SelectAll(ILayoutRepository Repository)
        //{
        //    return Repository.SelectAll();
        //}

        #endregion

        #region ADD LAYOUT

        public static Nullable <int> Add(InventioPage page, IPageRepository Repository)
        {
            Nullable <int> ret = null;

            if (page != null)
            {
                ret = Repository.Create(page);
            }

            return(ret);
        }
Пример #4
0
        public void Update(InventioPage page)
        {
            Pages data = EFAdapter(page);

            using (InventioEntities context = new InventioEntities())
            {
                context.Pages.Attach(data);
                context.Entry(data).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Пример #5
0
        public static InventioPage SelectByPath(string path, IPageRepository repository)
        {
            InventioPage ret = null;

            if (!string.IsNullOrWhiteSpace(path))
            {
                ret = repository.SelectByPath(path.Replace("~", string.Empty));
            }


            return(ret);
        }
Пример #6
0
        public static bool IsInventioPage(string path)
        {
            bool ret = false;

            if (!string.IsNullOrWhiteSpace(path))
            {
                InventioPage selected = PageWorker.SelectByPath(path, PageWorker.RepositoryWebConfig);
                ret = selected != null;
            }

            return(ret);
        }
Пример #7
0
        public InventioPage SelectById(int id)
        {
            InventioPage ret = null;

            ret = Read(id);
            if (ret == null)
            {
                ret       = new InventioPage();
                ret.Title = "Not found";
                //ret.Body = Encoding.UTF8.GetBytes("<h1>404</h1><p>Hola @ViewBag.Name</p>");
            }

            return(ret);
        }
Пример #8
0
        public InventioPage SelectByPath(string path)
        {
            InventioPage ret = null;

            using (InventioEntities context = new InventioEntities())
            {
                Pages selected = context.Pages.FirstOrDefault <Pages>(p => p.Path.ToLower() == path.ToLower());
                if (selected != null)
                {
                    ret = InventioAdapter(selected);
                }
            }

            return(ret);
        }
Пример #9
0
        public InventioPage Read(int id)
        {
            InventioPage ret = new InventioPage();

            using (InventioEntities context = new InventioEntities())
            {
                Pages selected = context.Pages.Where <Pages>(p => p.Id == id).FirstOrDefault <Pages>();
                if (selected != null)
                {
                    ret = InventioAdapter(selected);
                }
            }

            return(ret);
        }
Пример #10
0
 public static void RemovePage(string path)
 {
     if (!string.IsNullOrWhiteSpace(path))
     {
         InventioNavigationNode nav = NavigationWorker.SelectByPath(path, NavigationWorker.RepositoryWebConfig);
         if (nav != null)
         {
             NavigationWorker.Remove(nav.Id, NavigationWorker.RepositoryWebConfig);
         }                                                                                           // eliminamos navigation
         InventioPage page = PageWorker.SelectByPath(path, PageWorker.RepositoryWebConfig);
         if (page != null)
         {
             PageWorker.Remove(page.Id, PageWorker.RepositoryWebConfig);
         }                                                                                 // eliminamos página
     }
 }
Пример #11
0
        public Nullable <int> Create(InventioPage page)
        {
            Nullable <int> ret = null;

            // TODO CHECK PATH no existe ya !!!!

            Pages data = EFAdapter(page);

            using (InventioEntities context = new InventioEntities())
            {
                context.Pages.Add(data);
                context.SaveChanges();
                ret = data.Id;
            }

            return(ret);
        }
Пример #12
0
        public static void AddPage(string Path, string title, int IdLayout, Nullable <int> ParentId)
        {
            bool ok = !string.IsNullOrWhiteSpace(Path) && !string.IsNullOrWhiteSpace(title);

            if (ok)
            {
                // añadimos página
                InventioPage NewPage = new InventioPage();
                NewPage.Path     = Path + "/" + Tc.Inventio.Framework.Web.UrlHelper.Slug(title);
                NewPage.Title    = title;
                NewPage.IdLayout = IdLayout;
                PageWorker.Add(NewPage, PageWorker.RepositoryWebConfig);

                // añadimos entrada en navigation
                InventioNavigationNode NewNode = new InventioNavigationNode();
                NewNode.NodeType = InventioNavigationNodeType.Page;
                NewNode.ParentId = ParentId;
                NewNode.Url      = NewPage.Path;
                NewNode.Title    = title;
                NavigationWorker.Add(NewNode, NavigationWorker.RepositoryWebConfig);
            }
        }
Пример #13
0
        public InventioPage InventioAdapter(Pages page)
        {
            InventioPage ret = null;

            if (page != null)
            {
                ret = new InventioPage();

                ret.Id = page.Id;
                //ret.Page_Guid = page.GUID;  // TODO
                ret.Path            = page.Path;
                ret.Title           = page.Title;
                ret.IdLayout        = page.LayoutId;
                ret.State           = (InventioPageStates)page.State;
                ret.PubVersion      = page.PubVersion;
                ret.MetaData        = page.Metadata;
                ret.MetaDataVersion = page.MetadataVersion;
                ret.Action          = (InventioPageAction)page.Action;
                ret.IdUser          = page.IdUser.HasValue ? page.IdUser.Value : -1;
            }

            return(ret);
        }
Пример #14
0
        //private List<InventioNavigationNode> StringToChilds(string childs)
        //{
        //    List<InventioNavigationNode> ret = string.Empty;

        //    if (!string.IsNullOrWhiteSpace(childs))
        //    {
        //        foreach (InventioNavigationNode node in childs)
        //        {
        //            ret = string.Concat(";", ret, node.Id);
        //        }

        //        ret = ret.Substring(1); // quitamos el primer ';'
        //    }



        //    return ret;
        //}

        public Pages EFAdapter(InventioPage page)
        {
            Pages ret = null;

            if (page != null)
            {
                ret      = new Pages();
                ret.Id   = page.Id;
                ret.GUID = page.Page_Guid != null?page.Page_Guid.ToString("B") : string.Empty;

                ret.Path            = page.Path;
                ret.Title           = page.Title;
                ret.LayoutId        = page.IdLayout;
                ret.State           = (int)page.State;
                ret.PubVersion      = page.PubVersion;
                ret.Metadata        = page.MetaData;
                ret.MetadataVersion = page.MetaDataVersion;
                ret.Action          = (int)page.Action;
                ret.IdUser          = page.IdUser;
            }

            return(ret);
        }