private ActionComponentSetup getFavoriteAction()
        {
            var text = "{0} Article ({1})".FormatWith(
                AppTools.User == null || FavoritesTableRetrieval.GetRowMatchingPk(AppTools.User.UserId, ArticleId, returnNullIfNoMatch: true) == null
                                        ? "Favorite"
                                        : "Unfavorite",
                FavoritesTableRetrieval.GetRows(new FavoritesTableEqualityConditions.ArticleId(ArticleId)).Count());
            var icon = new ActionComponentIcon(new FontAwesomeIcon("fa-heart"));

            return(AppTools.User == null
                                       ? (ActionComponentSetup) new HyperlinkSetup(User.GetInfo(), text, icon: icon)
                                       : new ButtonSetup(
                       text,
                       behavior: new PostBackBehavior(
                           postBack: FavoritesTableRetrieval.GetRowMatchingPk(AppTools.User.UserId, ArticleId, returnNullIfNoMatch: true) == null
                                                                         ? PostBack.CreateFull(
                               id: "favorite",
                               modificationMethod: () => FavoritesModification.InsertRow(AppTools.User.UserId, ArticleId))
                                                                         : PostBack.CreateFull(
                               id: "unfavorite",
                               modificationMethod: () => FavoritesModification.DeleteRows(
                                   new FavoritesTableEqualityConditions.UserId(AppTools.User.UserId),
                                   new FavoritesTableEqualityConditions.ArticleId(ArticleId)))),
                       icon: icon));
        }
示例#2
0
        private static PhrasingComponent getFavoriteActionComponent(
            ArticlesRetrieval.Row article, ILookup <int, FavoritesTableRetrieval.Row> favoritesByArticleId)
        {
            var count = favoritesByArticleId[article.ArticleId].Count().ToString();

            if (AppTools.User == null)
            {
                return(new EwfHyperlink(User.GetInfo(), new StandardHyperlinkStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart-o")))));
            }

            var       rs = new UpdateRegionSet();
            EwfButton button;

            if (FavoritesTableRetrieval.GetRowMatchingPk(AppTools.User.UserId, article.ArticleId, returnNullIfNoMatch: true) == null)
            {
                button = new EwfButton(
                    new StandardButtonStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart-o"))),
                    behavior: new PostBackBehavior(
                        postBack: PostBack.CreateIntermediate(
                            rs.ToCollection(),
                            id: PostBack.GetCompositeId("favorite", article.ArticleId.ToString()),
                            modificationMethod: () => FavoritesModification.InsertRow(AppTools.User.UserId, article.ArticleId))));
            }
            else
            {
                button = new EwfButton(
                    new StandardButtonStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart"))),
                    behavior: new PostBackBehavior(
                        postBack: PostBack.CreateIntermediate(
                            rs.ToCollection(),
                            id: PostBack.GetCompositeId("unfavorite", article.ArticleId.ToString()),
                            modificationMethod: () => FavoritesModification.DeleteRows(
                                new FavoritesTableEqualityConditions.UserId(AppTools.User.UserId),
                                new FavoritesTableEqualityConditions.ArticleId(article.ArticleId)))));
            }
            return(new PhrasingIdContainer(button.ToCollection(), updateRegionSets: rs.ToCollection()));
        }