Exemple #1
0
        private async Task <IEnumerable <Post> > GetPostInternal(
            int?id,
            string slug,
            int?top,
            int?skip,
            DateTime?startdate,
            DateTime?enddate,
            bool includeUnpublished,
            bool includeDeleted,
            IEnumerable <string> tags)
        {
            var results = await this.ExecuteReader(
                "cati.getposts",
                parmeters =>
            {
                parmeters.AddWithValue("id", id);
                parmeters.AddWithValue("slug", slug);
                parmeters.AddWithValue("top", top);
                parmeters.AddWithValue("skip", skip);
                parmeters.AddWithValue("startdate", startdate);
                parmeters.AddWithValue("enddate", enddate);
                parmeters.AddWithValue("includeUnpublished", includeUnpublished);
                parmeters.AddWithValue("includeDeleted", includeDeleted);
                var tagslist       = parmeters.AddWithValue("tags", CatiSqlDataLayer.GetPostTagRecords(tags));
                tagslist.SqlDbType = SqlDbType.Structured;
                tagslist.TypeName  = "cati.tagslist";
            },
                SqlParsers.ParsePostMeta,
                SqlParsers.ParsePostContent,
                SqlParsers.ParsePostTag,
                SqlParsers.ParsePostAuditMapping);

            var postContentlookup = results.Item2.ToLookup(c => c.PostId);
            var tagsLookup        = results.Item3.ToLookup(t => t.PostId);
            var historyLookup     = results.Item4.ToLookup(a => a.PostId);

            // Get the tag mapping.
            foreach (var metadata in results.Item1)
            {
                if (tagsLookup.Contains(metadata.Id))
                {
                    metadata.Tags = tagsLookup[metadata.Id].Select(t => t.Tag);
                }

                if (historyLookup.Contains(metadata.Id))
                {
                    metadata.History = historyLookup[metadata.Id].Select(a => a.ToPostAuditHistory());
                }
            }

            return(results.Item1.Select(meta => new Post(meta, postContentlookup.First(m => m.Key == meta.Id))));
        }
Exemple #2
0
        /// <summary>
        /// Set a post.
        /// </summary>
        /// <param name="post">The post.</param>
        /// <param name="userAccessDetails">The user access details.</param>
        /// <returns>An async task.</returns>
        public async Task <Post> SetPost(Post post, UserAccessDetails userAccessDetails)
        {
            var results = await this.ExecuteReader(
                "cati.setpost",
                parmeters =>
            {
                parmeters.AddWithValue("id", post.MetaData.Id <= 0 ? null : (int?)post.MetaData.Id);
                parmeters.AddWithValue("slug", post.MetaData.Slug);
                parmeters.AddWithValue("title", post.MetaData.Title);
                parmeters.AddWithValue("description", post.MetaData.Description);
                parmeters.AddWithValue("userid", userAccessDetails.UserId);
                parmeters.AddWithValue("goeslive", post.MetaData.GoesLive);
                parmeters.AddWithValue("ispublished", post.MetaData.IsPublished);
                parmeters.AddWithValue("isreserved", post.MetaData.IsReserved);
                parmeters.AddWithValue("revision", post.MetaData.Revision);
                parmeters.AddWithValue("defaultimageid", (object)post.MetaData.DefaultImageId ?? DBNull.Value);
                parmeters.AddWithValue("publisheduser", post.MetaData.PublishedUser);

                var contentList = parmeters.AddWithValue(
                    "content",
                    CatiSqlDataLayer.GetPostContentRecord(post.PostContent));
                contentList.SqlDbType = SqlDbType.Structured;
                contentList.TypeName  = "cati.postcontentlist";
                var tagslist          = parmeters.AddWithValue(
                    "tags",
                    CatiSqlDataLayer.GetPostTagRecords(post.MetaData.Tags));
                tagslist.SqlDbType = SqlDbType.Structured;
                tagslist.TypeName  = "cati.tagslist";
            },
                SqlParsers.ParsePostMeta,
                SqlParsers.ParsePostContent,
                SqlParsers.ParsePostTag,
                SqlParsers.ParsePostAuditMapping);

            var metadata = results.Item1.First();
            var tags     = results.Item3;

            metadata.Tags = tags.Select(t => t.Tag);

            var history = results.Item4;

            metadata.History = history.Select(h => h.ToPostAuditHistory());

            return(new Post(results.Item1.First(), results.Item2));
        }