Ejemplo n.º 1
0
            private async Task <string> GetCalculatedPropertyAsync(string name)
            {
                string sql = null;

                if (name == "CommentsUnapproved")
                {
                    using (DataProvider.BlogCommentDataProvider commentDP = new DataProvider.BlogCommentDataProvider(-1)) {// we don't know the entry, but it's not needed
                        sql = "SELECT COUNT(*) FROM $BlogComments$ WHERE ($BlogComments$.\"EntryIdentity\" = $ThisTable$.\"Identity\") AND ($ThisTable$.\"Published\" = True) AND ($BlogComments$.\"Deleted\" = False) AND ($BlogComments$.\"Approved\" = False)";
                        IPostgreSQLTableInfo info = await commentDP.GetDataProvider().GetIPostgreSQLTableInfoAsync();

                        sql = info.ReplaceWithTableName(sql, "$BlogComments$");
                        sql = ReplaceWithTableName(sql, "$ThisTable$");
                    }
                }
                else if (name == "Comments")
                {
                    using (DataProvider.BlogCommentDataProvider commentDP = new DataProvider.BlogCommentDataProvider(-1)) {// we don't know the entry, but it's not needed
                        sql = "SELECT COUNT(*) FROM $BlogComments$ WHERE ($BlogComments$.\"EntryIdentity\" = $ThisTable$.\"Identity\") AND ($ThisTable$.\"Published\" = True)";
                        IPostgreSQLTableInfo info = await commentDP.GetDataProvider().GetIPostgreSQLTableInfoAsync();

                        sql = info.ReplaceWithTableName(sql, "$BlogComments$");
                        sql = ReplaceWithTableName(sql, "$ThisTable$");
                    }
                }
                else
                {
                    throw new InternalError("Unexpected property {0}", name);
                }
                return(sql);
            }
Ejemplo n.º 2
0
            private async Task <object> GetCalculatedPropertyAsync(string name, object obj)
            {
                BlogEntry entry = (BlogEntry)obj;

                if (name == "CommentsUnapproved")
                {
                    using (DataProvider.BlogCommentDataProvider commentDP = new DataProvider.BlogCommentDataProvider(entry.Identity)) {
                        List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo>()
                        {
                            new DataProviderFilterInfo {
                                Field = nameof(BlogComment.Approved), Operator = "==", Value = false,
                            },
                        };
                        DataProviderGetRecords <BlogComment> commentsUnapproved = await commentDP.GetItemsAsync(0, 0, null, filters);

                        entry.CommentsUnapproved = commentsUnapproved.Total;
                        return(obj);
                    }
                }
                else if (name == "Comments")
                {
                    using (DataProvider.BlogCommentDataProvider commentDP = new DataProvider.BlogCommentDataProvider(entry.Identity)) {
                        DataProviderGetRecords <BlogComment> comments = await commentDP.GetItemsAsync(0, 0, null, null);

                        entry.Comments = comments.Total;
                        return(obj);
                    }
                }
                else
                {
                    throw new InternalError("Unexpected property {0}", name);
                }
            }