Example #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);
            }
        }
Example #2
0
            //front end
            public static Core.Models.Page Retrieve(string t, string s = "", string p = "")
            {
                DB.Context db = new DB.Context();
                IRepository<Core.Models.Page> repo = new DB.Repository<Core.Models.Page>(db);

                //tab link
                if (!string.IsNullOrEmpty(t))
                {
                    Tab tab = db.Tabs.SingleOrDefault(x => x.UrlTitle.Equals(t));
                    if (tab != null)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            Section sec = tab.Sections.SingleOrDefault(x => x.UrlTitle.Equals(s));
                            if (sec != null)
                            {
                                if (!string.IsNullOrEmpty(p))
                                {
                                    Link l = sec.Links.SingleOrDefault(x => x.UrlTitle.Equals(p));
                                    if (l != null)
                                    {
                                        //return Link Page
                                        return repo.RetrieveById(l.PageId);
                                    }
                                    else
                                    {
                                        return null;
                                    }
                                }
                                else
                                {
                                    //return Section Page
                                    return repo.RetrieveById(sec.PageId);
                                }
                            }
                            else
                            {
                                return null;
                            }
                        }
                        else
                        {
                            //return Tab Page
                            return repo.RetrieveById(tab.PageId);
                        }
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    //home page
                    return repo.SingleOrDefault(x => x.IsHomePage == true);
                }
            }
Example #3
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);
            }
        }
        //Introduction Paragraph
        public ActionResult Intro(int pageId = 0)
        {
            ViewData["PageId"] = pageId.ToString();
            IEnumerable<PageComponent> comps = repo.Retrieve(x => x.PageId == pageId);
            IRepository<Intro> iRepo = new DB.Repository<Intro>(this.db);
            Intro intro = new Intro();

            if (comps != null)
            {
                if (comps.Count() > 0)
                {
                    PageComponent c = comps.First(x => x.ComponentType.Equals(Engine.Component.Type.Intro.ToString()));
                    if (c != null)
                    {
                        intro = iRepo.RetrieveById(c.ComponentId);
                    }
                }
            }

            return View(intro);
        }
Example #5
0
 //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;
 }
Example #6
0
                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;
                }
Example #7
0
                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;
                }
Example #8
0
 public static string Template(int? id)
 {
     if (id != null)
     {
         IRepository<Core.Models.Page> repo = new DB.Repository<Core.Models.Page>(new DB.Context());
         return repo.RetrieveById(id).Template;
     }
     return "";
 }
        public ActionResult Intro(int pageId, string rte)
        {
            ViewData["PageId"] = pageId;
            Page p = db.Set<Page>().Find(pageId);
            IEnumerable<PageComponent> comps = repo.Retrieve(x => x.PageId == pageId);
            IRepository<Intro> iRepo = new DB.Repository<Intro>(this.db);
            Intro intro = null;

            if (comps != null)
            {
                if (comps.Count() > 0)
                {
                    PageComponent c = comps.First(x => x.ComponentType.Equals(Engine.Component.Type.Intro.ToString()));
                    if (c != null)
                    {
                        intro = iRepo.RetrieveById(c.ComponentId);
                    }
                }
            }

            bool bSaved = false;
            if (intro != null)
            {
                //update
                intro.Content = HttpUtility.HtmlEncode(rte);
                TryUpdateModel(intro);
                if (ModelState.IsValid)
                {
                    try
                    {
                        iRepo.Update(intro);
                        iRepo.Save();
                        bSaved = true;
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                        Error.Exception(ex, "/Component/Intro");
                        bSaved = false;
                    }
                }
                else
                {
                    bSaved = false;
                    ModelState.AddModelError("", Config.Error.Message.Generic);
                }
            }
            else
            {
                //insert
                Intro i = new Models.Intro();
                i.Content = HttpUtility.HtmlEncode(rte);

                if (ModelState.IsValid)
                {
                    try
                    {
                        iRepo.Add(i);
                        iRepo.Save();

                        PageComponent pgc = new PageComponent();
                        pgc.Page = p;
                        pgc.ComponentId = i.Id;
                        pgc.ComponentType = Engine.Component.Type.Intro.ToString();

                        try
                        {
                            repo.Add(pgc);
                            repo.Save();
                            bSaved = true;
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.Message);
                            Error.Exception(ex, "/Component/Intro");
                            bSaved = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                        Error.Exception(ex, "/Component/Intro");
                        bSaved = false;
                    }
                }
                else
                {
                    bSaved = false;
                    ModelState.AddModelError("", Config.Error.Message.Generic);
                }

            }

            if (bSaved)
            {
                return RedirectToAction("Index", "Page");
            }

            return View(intro);
        }
Example #10
0
                    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);
                    }
Example #11
0
                    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);
                    }
Example #12
0
                    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);
                    }
Example #13
0
                    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);
                    }
Example #14
0
                    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);
                    }
Example #15
0
 public static Core.Models.Tab Info(int id)
 {
     IRepository<Core.Models.Tab> repo = new DB.Repository<Core.Models.Tab>(new DB.Context());
     return repo.RetrieveById(id);
 }
Example #16
0
 public static string IdBySection(int id)
 {
     IRepository<Core.Models.Section> repo = new DB.Repository<Core.Models.Section>(new DB.Context());
     return repo.RetrieveById(id).TabId.ToString();
 }
Example #17
0
 public static Core.Models.Page RetrieveById(int pageId)
 {
     IRepository<Core.Models.Page> repo = new DB.Repository<Core.Models.Page>(new DB.Context());
     return repo.RetrieveById(pageId);
 }
Example #18
0
        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" });
            }
        }