Beispiel #1
0
        TableStoragePost SetPost(Post post)
        {
            //is there any better options for partition and row key? I'm not quite sure
            var p = new TableStoragePost
            {
                PartitionKey = post.ID,
                RowKey       = post.ID,
                ID           = post.ID,
                Title        = post.Title,
                Slug         = post.Slug,
                Excerpt      = post.Excerpt,
                Content      = post.Content,
                PubDate      = post.PubDate,
                LastModified = post.LastModified,
                IsPublished  = post.IsPublished,
                Categories   = JsonConvert.SerializeObject(post.Categories),
                Comments     = JsonConvert.SerializeObject(post.Comments),
            };

            return(p);
        }
Beispiel #2
0
        Post GetPost(TableStoragePost post)
        {
            var p = new Post
            {
                ID           = post.ID,
                Title        = post.Title,
                Slug         = post.Slug,
                Excerpt      = post.Excerpt,
                Content      = post.Content,
                PubDate      = post.PubDate,
                LastModified = post.LastModified,
                IsPublished  = post.IsPublished,
                Categories   = JsonConvert.DeserializeObject <List <string> >(post.Categories)
            };

            //Need to double check, but it seems that this is not needed since Categories may never be null
            //if (!string.IsNullOrWhiteSpace(post.Categories))
            //{
            //    var categories = JsonConvert.DeserializeObject<List<string>>(post.Categories);
            //    p.Categories = categories;
            //}

            if (!string.IsNullOrWhiteSpace(post.Comments))
            {
                var comments = JsonConvert.DeserializeObject <List <Comment> >(post.Comments);
                if (comments != null && comments.Count > 0)
                {
                    foreach (var comment in comments)
                    {
                        p.Comments.Add(comment);
                    }
                }
            }

            return(p);
        }