Пример #1
0
 public IJsonResponse <IEnumerable <object> > Upload(string pathPrefix, HttpPostedFileBase[] file)
 {
     return(JsonResponse.Catch(() => {
         var res = _ui.Files.UploadFiles(_domain, pathPrefix, file).ToList();
         _ui.UnitOfWork.Commit();
         return res.Select(f => AttachmentJson(f.Id, f.FilePath, f.Data.ContentType));
     }, _ui.Log));
 }
Пример #2
0
 public JsonResponse <IEnumerable <JS.Page> > All()
 {
     return(JsonResponse.Catch(() =>
                               Pages.All.Where(p => p.SiteId == Sites.CurrentSiteId)
                               .AsEnumerable().Select(p => new JS.Page {
         Id = p.Id, Path = p.Url
     }), Log));
 }
Пример #3
0
 public IJsonResponse <IEnumerable <object> > GetAll()
 {
     return(JsonResponse.Catch(() => _ui
                               .Files.GetAll(_domain)
                               .Select(f => new { f.Id, f.FilePath, f.Data.ContentType })
                               .AsEnumerable()
                               .Select(f => AttachmentJson(f.Id, f.FilePath, f.ContentType)), _ui.Log));
 }
Пример #4
0
 public JsonResponse <JS.TextView> LoadHtml(string id)
 {
     return(JsonResponse.Catch(() => {
         var p = Texts.All.FirstOrDefault(x => x.Id == id && x.SiteId == Sites.CurrentSiteId);
         return new JS.TextView {
             Text = p == null ? "" : p.HtmlText, AllowEdit = Auth.CurrentActor.IsAdmin
         };
     }, Log));
 }
Пример #5
0
 public JsonResponse <JS.TextEditor> Load(string id)
 {
     return(JsonResponse.Catch(() => {
         var p = Texts.All.FirstOrDefault(x => x.Id == id && x.SiteId == Sites.CurrentSiteId);
         return JsonResponse.Create(new JS.TextEditor {
             Id = id, Text = p == null ? "" : p.BbText
         });
     }, Log));
 }
Пример #6
0
        public JsonResponse <IEnumerable <JS.Menu.Item> > UpdateSubItems(JS.Menu.SubItemsSaveRequest req)
        {
            return(JsonResponse.Catch(() => {
                var items = TopMenu.GetItemsForParent(null, req.MenuId).ToList();
                UpdateItems(null, req.MenuId, items, req.Items.EmptyIfNull());
                UnitOfWork.Commit();

                return Load(req.MenuId);
            }, Log));
        }
Пример #7
0
 public JsonResponse <JS.Page> Create([JsonRequestBodyAttribute] JS.Page page)
 {
     return(JsonResponse.Catch(() => {
         var p = Pages.Add(new Page {
             Url = page.Path, SiteId = Sites.CurrentSiteId
         });
         UnitOfWork.Commit();
         return new JS.Page {
             Id = p.Id, Path = p.Url
         };
     }, Log));
 }
Пример #8
0
 public JsonResponse <Unit> Update([JsonRequestBodyAttribute] JS.Page page)
 {
     return(JsonResponse.Catch(() => {
         var p = Pages.All.FirstOrDefault(x => x.Id == page.Id && x.SiteId == Sites.CurrentSiteId);
         if (p == null)
         {
             return JsonResponse <Unit> .NotFound;
         }
         p.Url = page.Path;
         p.Modified = DateTime.Now;
         UnitOfWork.Commit();
         return JsonResponse <Unit> .Void;
     }, Log));
 }
Пример #9
0
        public JsonResponse <JS.PageEditor> Load(int id)
        {
            return(JsonResponse.Catch(() => {
                var p = Pages.All.FirstOrDefault(x => x.Id == id && x.SiteId == Sites.CurrentSiteId);
                if (p == null)
                {
                    return JsonResponse <JS.PageEditor> .NotFound;
                }

                return JsonResponse.Create(new JS.PageEditor {
                    Id = id, Path = p.Url, Text = p.BbText ?? "", Title = p.Title ?? "",
                    TagsStandIn = p.TagsStandIn, ReferenceName = p.ReferenceName ?? ""
                });
            }, Log));
        }
Пример #10
0
        public JsonResponse <JS.TextSaveResult> Update([JsonRequestBody] JS.TextEditor text)
        {
            return(JsonResponse.Catch(() => {
                var p = Texts.All.FirstOrDefault(x => x.Id == text.Id && x.SiteId == Sites.CurrentSiteId);
                if (p == null)
                {
                    p = Texts.Add(new Data.Text {
                        Id = text.Id, SiteId = Sites.CurrentSiteId
                    });
                }

                p.BbText = text.Text;
                p.HtmlText = Markup.ToHtml(p.BbText ?? "", new MarkdownParseArgs {
                    AttachmentMixin = Url.Mixin(( TextController c ) => c.Attachment(text.Id))
                });
                UnitOfWork.Commit();

                return JsonResponse.Create(new JS.TextSaveResult {
                    Html = p.HtmlText
                });
            }, Log));
        }
Пример #11
0
        public JsonResponse <JS.PageSaveResult> Update([JsonRequestBody] JS.PageEditor page)
        {
            return(JsonResponse.Catch(() => {
                var p = Pages.All.FirstOrDefault(x => x.Id == page.Id && x.SiteId == Sites.CurrentSiteId);
                if (p == null)
                {
                    return JsonResponse <JS.PageSaveResult> .NotFound;
                }

                p.Title = page.Title ?? "";
                p.BbText = page.Text;
                p.TagsStandIn = page.TagsStandIn;
                p.ReferenceName = page.ReferenceName;
                p.HtmlText = Markup.ToHtml(p.BbText ?? "", new MarkdownParseArgs {
                    AttachmentMixin = Url.Mixin((PageController c) => c.Attachment(page.Id))
                });
                UnitOfWork.Commit();

                return JsonResponse.Create(new JS.PageSaveResult {
                    Title = p.Title, Html = p.HtmlText
                });
            }, Log));
        }
Пример #12
0
 public IJsonResponse <string> ToHtml(string bbText)
 {
     return(JsonResponse.Catch(() =>
                               UI.ToHtml(bbText, new MarkdownParseArgs()), Log));
 }
Пример #13
0
 public JsonResponse <IEnumerable <JS.Menu.Item> > Load(string menuId)
 {
     return(JsonResponse.Catch(() => TopMenu.GetItemsForParent(null, menuId).Select(TopMenu.ToJson), Log));
 }