Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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" });
            }
        }
Ejemplo n.º 3
0
        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);
        }