Esempio n. 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);
            }
        }
Esempio n. 2
0
        //default method returning JSON format
        public ActionResult Index(string jsonp = "")
        {
            Api.Response api = new Api.Response();
            List<Error.Message> error = new List<Error.Message>();

            if (!string.IsNullOrEmpty(jsonp))
            {
                return new Api.Response.Jsonp(api, jsonp);
            }
            else
            {
                return Json(api, JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 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);
            }
        }