protected override PageContent getContent() =>
 new UiPageContent(
     pageActions: AppTools.User != null && articleRow.AuthorId == AppTools.User.UserId
                                                      ? new HyperlinkSetup(
         Editor.GetInfo(ArticleId),
         "Edit Article",
         icon: new ActionComponentIcon(new FontAwesomeIcon("fa-pencil")))
     .Append <ActionComponentSetup>(
         new ButtonSetup(
             "Delete Article",
             behavior: new PostBackBehavior(
                 postBack: PostBack.CreateFull(
                     id: "delete",
                     modificationMethod: () => {
     ArticleTagsModification.DeleteRows(new ArticleTagsTableEqualityConditions.ArticleId(ArticleId));
     ArticlesModification.DeleteRows(new ArticlesTableEqualityConditions.ArticleId(ArticleId));
 },
                     actionGetter: () => new PostBackAction(Home.GetInfo()))),
             icon: new ActionComponentIcon(new FontAwesomeIcon("fa-trash"))))
     .Materialize()
                                                      : AppStatics.GetFollowAction(articleRow.AuthorId).Append(getFavoriteAction()).Materialize())
 .Add(AppStatics.GetAuthorDisplay(articleRow, UsersTableRetrieval.GetRowMatchingId(articleRow.AuthorId)))
 .Add(new HtmlBlockContainer(Markdown.ToHtml(articleRow.BodyMarkdown)))
 .Add(AppStatics.GetTagDisplay(ArticleId, ArticleTagsTableRetrieval.GetRowsLinkedToArticle(ArticleId)))
 .Add(getCommentComponents());
Ejemplo n.º 2
0
        protected override PageContent getContent()
        {
            var mod    = getMod();
            var tagIds = ComponentStateItem.Create(
                "tags",
                ArticleId.HasValue
                                        ? ArticleTagsTableRetrieval.GetRowsLinkedToArticle(ArticleId.Value).Select(i => i.TagId).Materialize()
                                        : Enumerable.Empty <int>().Materialize(),
                v => v.All(id => TagsTableRetrieval.GetRowMatchingId(id, returnNullIfNoMatch: true) != null),
                true);

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(
                           modificationMethod: () => {
                if (!ArticleId.HasValue)
                {
                    mod.ArticleId = MainSequence.GetNextValue();
                    mod.Slug = getSuffixedSlug(mod.Title.ToUrlSlug());
                    mod.CreationDateAndTime = DateTime.UtcNow;
                }
                mod.Execute();

                if (ArticleId.HasValue)
                {
                    ArticleTagsModification.DeleteRows(new ArticleTagsTableEqualityConditions.ArticleId(ArticleId.Value));
                }
                foreach (var i in tagIds.Value.Value)
                {
                    ArticleTagsModification.InsertRow(mod.ArticleId, i);
                }
            },
                           actionGetter: () => new PostBackAction(Article.GetInfo(mod.ArticleId)))
                       .ToCollection(),
                       () => {
                var stack = FormItemList.CreateStack(generalSetup: new FormItemListSetup(etherealContent: tagIds.ToCollection()));

                stack.AddItems(
                    mod.GetTitleTextControlFormItem(false, label: "Article title".ToComponents(), value: ArticleId.HasValue ? null : "")
                    .Append(
                        mod.GetDescriptionTextControlFormItem(false, label: "What's this article about?".ToComponents(), value: ArticleId.HasValue ? null : ""))
                    .Append(
                        mod.GetBodyMarkdownTextControlFormItem(
                            false,
                            label: "Write your article (in markdown)".ToComponents(),
                            controlSetup: TextControlSetup.Create(numberOfRows: 8),
                            value: ArticleId.HasValue ? null : ""))
                    .Append(getTagFormItem(tagIds.Value))
                    .Materialize());

                return new UiPageContent(contentFootActions: new ButtonSetup("Publish Article").ToCollection()).Add(stack);
            }));
        }