//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); } }
//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); }
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); }
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; }
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 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" }); } }
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); }
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(); }
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); }