コード例 #1
0
        public ActionResult GetPagesByTmpl(string tmpl, string jsonp = "")
        {
            Api.Response api = new Api.Response();
            List<Error.Message> error = new List<Error.Message>();

            IRepository<Page> repo = new DB.Repository<Page>(new DB.Context());
            IEnumerable<Page> data = repo.Retrieve(x => x.Template.Equals(tmpl), m => m.OrderBy(x => x.Title), null);
            if (data != null)
            {
                var pages = from page in data
                            select new
                            {
                                id = page.Id,
                                title = page.Title
                            };
                api.Result = pages;
                api.Success = true;
            }
            else
            {
                error.Add(new Error.Message { Id = "", Text = Config.Error.Message.Generic });
                api.Success = false;
                api.Errors = error;
            }

            if (!string.IsNullOrEmpty(jsonp))
            {
                return new Api.Response.Jsonp(api, jsonp);
            }
            else
            {
                return Json(api, JsonRequestBehavior.DenyGet);
            }
        }
コード例 #2
0
        public ActionResult SaveAccordionItemsOrder(int pageId, string order, string delim, string jsonp = "")
        {
            Api.Response api = new Api.Response();
            List<Error.Message> error = new List<Error.Message>();

            string[] arr = Utils.Array.FromString(order, delim);

            DB.Context db = new DB.Context();
            IRepository<Accordion> repo = new DB.Repository<Accordion>(db);
            IEnumerable<Accordion> data = repo.Retrieve(x => x.PageId == pageId, m => m.OrderBy(x => x.Position), null);
            int ctr = 1;
            foreach (string id in arr)
            {
                try
                {
                    Accordion item = data.Single(x => x.Id == Convert.ToInt32(id));
                    item.Position = ctr;
                    repo.Update(item);
                    ctr++;
                }
                catch (Exception ex)
                {
                    Error.Exception(ex, "/API/Engine/SaveAccordionItemsOrder PageID: " + pageId.ToString() + " ID: " + id);
                }
            }

            try
            {
                repo.Save();
                api.Success = true;
            }
            catch (Exception exc)
            {
                Error.Exception(exc, "AccordionPage/SaveOrder");
                error.Add(new Error.Message { Id = "", Text = Config.Error.Message.Generic });
                api.Success = false;
                api.Errors = error;
            }

            if (!string.IsNullOrEmpty(jsonp))
            {
                return new Api.Response.Jsonp(api, jsonp);
            }
            else
            {
                return Json(api, JsonRequestBehavior.DenyGet);
            }
        }
コード例 #3
0
ファイル: Page.cs プロジェクト: webitpro/SimpleCore
 //back end
 public static bool HomePageExists()
 {
     IRepository<Core.Models.Page> repo = new DB.Repository<Core.Models.Page>(new DB.Context());
     return repo.Retrieve(x => x.IsHomePage == true, null, null).Count() > 0;
 }
コード例 #4
0
ファイル: Page.cs プロジェクト: webitpro/SimpleCore
                public static Core.Models.CustomPage Retrieve(int pageId)
                {
                    IRepository<Core.Models.CustomPage> repo = new DB.Repository<Core.Models.CustomPage>(new DB.Context());
                    IEnumerable<Core.Models.CustomPage> pages = repo.Retrieve(x => x.PageId == pageId, null, null);
                    Core.Models.CustomPage page = pages.SingleOrDefault(x => x.PageId == pageId);
                    if (page != null)
                    {
                        return page;
                    }

                    return null;
                }
コード例 #5
0
ファイル: Page.cs プロジェクト: webitpro/SimpleCore
                public static object Retrieve(int pageId, Engine.Component.Type type)
                {
                    object o = null;
                    IRepository<PageComponent> pcRepo = new DB.Repository<PageComponent>(new DB.Context());
                    IEnumerable<PageComponent> pcs = pcRepo.Retrieve(x => x.PageId == pageId);
                    if(pcs != null)
                    {
                        if (pcs.Count() > 0)
                        {
                            PageComponent pc = pcs.First(x=>x.ComponentType.Equals(type.ToString()));
                            if (pc != null)
                            {
                                IRepository<Intro> repo = new DB.Repository<Intro>(new DB.Context());
                                Intro i = repo.RetrieveById(pc.ComponentId);
                                if (i != null)
                                {
                                    o = i;
                                }
                            }
                        }
                    }

                    return o;
                }
コード例 #6
0
ファイル: PageController.cs プロジェクト: webitpro/SimpleCore
        public ActionResult Delete(int id)
        {
            Page p = repo.RetrieveById(id);
            if (p != null)
            {
                switch ((Engine.Template.Id)Enum.Parse(typeof(Engine.Template.Id), p.Template))
                {
                    case Engine.Template.Id.Custom_Page:
                        IRepository<CustomPage> cpRepo = new DB.Repository<CustomPage>(db);
                        IEnumerable<CustomPage> customPages = cpRepo.Retrieve(x => x.PageId == id, null, null);
                        if (customPages != null)
                        {
                            foreach (CustomPage cp in customPages)
                            {
                                cpRepo.Delete(cp.Id);
                                try { cpRepo.Save(); }
                                catch (Exception ex)
                                {
                                    Error.Exception(ex, "/Page/Delete/CustomPage");
                                }
                            }
                        }

                        break;
                    case Engine.Template.Id.Static_Page:
                        IRepository<StaticPage> spRepo = new DB.Repository<StaticPage>(db);
                        IEnumerable<StaticPage> staticPages = spRepo.Retrieve(x => x.PageId == id, null, null);
                        if (staticPages != null)
                        {
                            foreach (StaticPage sp in staticPages)
                            {
                                spRepo.Delete(sp.Id);
                                try { spRepo.Save(); }
                                catch (Exception ex)
                                {
                                    Error.Exception(ex, "/Page/Delete/StaticPage");
                                }
                            }
                        }
                        break;
                    case Engine.Template.Id.Accordion:
                        IRepository<PageComponent> pcRepo = new DB.Repository<PageComponent>(db);
                        IEnumerable<PageComponent> pcs = pcRepo.Retrieve(x => x.PageId == id, null, null);

                        if (pcs != null)
                        {
                            foreach (PageComponent pc in pcs)
                            {
                                switch ((Engine.Component.Type)Enum.Parse(typeof(Engine.Component.Type), pc.ComponentType))
                                {
                                    case Engine.Component.Type.Intro:
                                        IRepository<Intro> iRepo = new DB.Repository<Intro>(db);
                                        Intro i = iRepo.RetrieveById(pc.ComponentId);
                                        if (i != null)
                                        {
                                            iRepo.Delete(i.Id);
                                            try
                                            {
                                                iRepo.Save();
                                            }
                                            catch (Exception ex)
                                            {
                                                Error.Exception(ex, "/Page/Delete/Accordion - Component");
                                            }
                                        }
                                        break;
                                }

                                //delete from PageComponent table
                                pcRepo.Delete(pc.Id);
                                try
                                {
                                    pcRepo.Save();
                                }
                                catch(Exception ex)
                                {
                                    Error.Exception(ex, "/Page/Delete/Accordion - Page Component");
                                }
                            }
                        }

                        IRepository<Accordion> accRepo = new DB.Repository<Accordion>(db);
                        IEnumerable<Accordion> accordions = accRepo.Retrieve(x => x.PageId == id, null, null);
                        if (accordions != null)
                        {
                            foreach (Accordion acc in accordions)
                            {
                                accRepo.Delete(acc.Id);
                                try { accRepo.Save(); }
                                catch (Exception ex)
                                {
                                    Error.Exception(ex, "/Page/Delete/FAQ");
                                }
                            }
                        }
                        break;
                }
            }

            //check for connections with tab, section, link
            IRepository<Tab> tRepo = new DB.Repository<Tab>(db);
            IRepository<Section> sRepo = new DB.Repository<Section>(db);
            IRepository<Link> lRepo = new DB.Repository<Link>(db);
            IEnumerable<Link> links = lRepo.Retrieve(x => x.PageId == id, null, null);
            if (links != null)
            {
                foreach (Link l in links)
                {
                    lRepo.Delete(l.Id);
                    try
                    {
                        lRepo.Save();
                    }
                    catch (Exception ex)
                    {
                        Error.Exception(ex, "/Page/Delete - Link");
                    }
                }
            }
            IEnumerable<Section> sections = sRepo.Retrieve(x => x.PageId == id, null, null);
            if (sections != null)
            {
                foreach (Section s in sections)
                {
                    sRepo.Delete(s.Id);
                    try
                    {
                        sRepo.Save();
                    }
                    catch (Exception ex)
                    {
                        Error.Exception(ex, "/Page/Delete - Section");
                    }
                }
            }
            IEnumerable<Tab> tabs = tRepo.Retrieve(x => x.PageId == id, null, null);
            if (tabs != null)
            {
                foreach (Tab t in tabs)
                {
                    tRepo.Delete(t.Id);
                    try
                    {
                        tRepo.Save();
                    }
                    catch (Exception ex)
                    {
                        Error.Exception(ex, "/Page/Delete - Tabs");
                    }
                }
            }

            repo.Delete(id);
            try
            {
                repo.Save();
                return RedirectToAction("Index", "Page");
            }
            catch (Exception ex)
            {
                Error.Exception(ex, "/Page/Delete");
                TempData["PageDeleteError"] = Config.Error.Message.Generic;
                return RedirectToAction("Index", "Page", new { eid = "PageDeleteError" });
            }
        }
コード例 #7
0
ファイル: Form.cs プロジェクト: webitpro/SimpleCore
                    public static MultiSelectList Accordions(int pageId, int? selectedID)
                    {
                        List<SelectListItem> list = new List<SelectListItem>();
                        List<int> selectedValues = new List<int>();
                        DB.Context db = new DB.Context();
                        IRepository<Accordion> repo = new DB.Repository<Accordion>(db);
                        IEnumerable<Accordion> data = repo.Retrieve(x => x.PageId == pageId, m => m.OrderBy(x => x.Position), null);
                        if (data.Count() > 0)
                        {
                            foreach (Accordion item in data)
                            {
                                list.Add(new SelectListItem
                                {
                                    Text = item.Header,
                                    Value = item.Id.ToString(),
                                    Selected = ((selectedID != null) ? ((item.Id.Equals((int)selectedID)) ? true : false) : ((item.Id.Equals(data.First().Id)) ? true : false))
                                });
                            }

                            selectedValues.Add(((selectedID != null) ? (int)selectedID : data.First().Id));
                        }

                        return new MultiSelectList(list, "Value", "Text", selectedValues);
                    }
コード例 #8
0
ファイル: Form.cs プロジェクト: webitpro/SimpleCore
                    public static MultiSelectList Links(int sectionID, int? selectedID)
                    {
                        List<SelectListItem> list = new List<SelectListItem>();
                        List<int> selectedValues = new List<int>();
                        DB.Context db = new DB.Context();
                        IRepository<Link> repo = new DB.Repository<Link>(db);
                        IEnumerable<Link> links = repo.Retrieve(x => x.SectionId == sectionID, m => m.OrderBy(x => x.Position), null);
                        if (links.Count() > 0)
                        {
                            foreach (Link lnk in links)
                            {
                                list.Add(new SelectListItem
                                {
                                    Text = lnk.Title,
                                    Value = lnk.Id.ToString(),
                                    Selected = ((selectedID != null) ? ((lnk.Id.Equals((int)selectedID)) ? true : false) : ((lnk.Id.Equals(links.First().Id)) ? true : false))
                                });
                            }

                            selectedValues.Add(((selectedID != null) ? (int)selectedID : links.First().Id));
                        }
                        return new MultiSelectList(list, "Value", "Text", selectedValues);
                    }
コード例 #9
0
ファイル: Form.cs プロジェクト: webitpro/SimpleCore
                    public static MultiSelectList Sections(int tabID, int? selectedID)
                    {
                        List<SelectListItem> list = new List<SelectListItem>();
                        List<int> selectedValues = new List<int>();
                        DB.Context db = new DB.Context();
                        IRepository<Section> repo = new DB.Repository<Section>(db);
                        IEnumerable<Section> sections = repo.Retrieve(x => x.TabId == tabID, m => m.OrderBy(x => x.Position), null);
                        if (sections.Count() > 0)
                        {
                            foreach (Section s in sections)
                            {
                                list.Add(new SelectListItem
                                {
                                    Text = s.Title,
                                    Value = s.Id.ToString(),
                                    Selected = ((selectedID != null) ? ((s.Id.Equals((int)selectedID)) ? true : false) : ((s.Id.Equals(sections.First().Id)) ? true : false))
                                });
                            }

                            selectedValues.Add(((selectedID != null) ? (int)selectedID : sections.First().Id));
                        }

                        return new MultiSelectList(list, "Value", "Text", selectedValues);
                    }
コード例 #10
0
ファイル: Form.cs プロジェクト: webitpro/SimpleCore
                    public static MultiSelectList Tabs(int? selectedID)
                    {
                        List<SelectListItem> list = new List<SelectListItem>();
                        List<int> selectedValues = new List<int>();
                        DB.Context db = new DB.Context();
                        IRepository<Tab> repo = new DB.Repository<Tab>(db);
                        IEnumerable<Tab> tabs = repo.Retrieve(null, m => m.OrderBy(x => x.Position), null);
                        if (tabs.Count() > 0)
                        {
                            foreach (Tab t in tabs)
                            {
                                list.Add(new SelectListItem
                                {
                                    Text = t.Title,
                                    Value = t.Id.ToString(),
                                    Selected = ((selectedID != null) ? ((t.Id.Equals((int)selectedID)) ? true : false) : ((t.Id.Equals(tabs.First().Id)) ? true : false))
                                });
                            }

                            selectedValues.Add(((selectedID != null) ? (int)selectedID : tabs.First().Id));
                        }
                        return new MultiSelectList(list, "Value", "Text", selectedValues);
                    }
コード例 #11
0
ファイル: Form.cs プロジェクト: webitpro/SimpleCore
                    public static SelectList Sections(int selected)
                    {
                        List<SelectListItem> list = new List<SelectListItem>();
                        IRepository<Section> repo = new DB.Repository<Section>(new DB.Context());
                        IEnumerable<Section> data = repo.Retrieve(null, m => m.OrderBy(x => x.Position), null);
                        foreach (var s in data)
                        {
                            list.Add(new SelectListItem
                            {
                                Text = s.Title,
                                Value = s.Id.ToString(),
                                Selected = ((selected == s.Id) ? true : ((s.Id == data.First().Id) ? true : false))
                            });
                        }

                        return new SelectList(list, "Value", "Text", selected);
                    }