示例#1
0
        private PostQueryRow ProcessMultiResults(DynamicSql query, object[] objs)
        {
            var row = new PostQueryRow();

            for (var i = 0; i < query.MultiResults.Count; i++)
            {
                var r = query.MultiResults[i];
                switch (r.Key)
                {
                case PostQueryProjection.INFO: row.Post = objs[i] as Post; break;

                case PostQueryProjection.CONTENT: row.Content = objs[i] as PostContentRelationship; break;

                case PostQueryProjection.OWNER: row.Owner = objs[i] as OwnerRelationship; break;
                }
            }
            return(row);
        }
示例#2
0
        public IDictionary <string, object> GetPostDynamic(
            PostQueryRow row, PostQueryProjection projection,
            PostQueryOptions options)
        {
            var obj = new Dictionary <string, object>();

            foreach (var f in projection.GetFieldsArr())
            {
                switch (f)
                {
                case PostQueryProjection.INFO:
                {
                    var entity  = row.Post;
                    var content = row.Content;
                    obj["id"]        = entity.Id;
                    obj["owner_id"]  = entity.OwnerId;
                    obj["type"]      = entity.Type;
                    obj["archived"]  = entity.Archived;
                    obj["image_url"] = entity.ImageUrl;
                    var createdTime = entity.CreatedTime
                                      .ToTimeZone(options.time_zone, options.culture, content?.Lang);
                    var createdTimeStr = createdTime.ToString(options.date_format, options.culture, content?.Lang);
                    obj["created_time"] = new
                    {
                        display = createdTimeStr,
                        iso     = $"{createdTime.ToUniversalTime():s}Z"
                    };
                    var visibleTime = entity.VisibleTime?
                                      .ToTimeZone(options.time_zone, options.culture, content?.Lang);
                    var visibleTimeStr = visibleTime?.ToString(options.date_format, options.culture, content?.Lang);
                    if (visibleTimeStr != null)
                    {
                        obj["visible_time"] = new
                        {
                            display = visibleTimeStr,
                            iso     = $"{visibleTime?.ToUniversalTime():s}Z"
                        }
                    }
                    ;
                }
                break;

                case PostQueryProjection.CONTENT:
                {
                    var entity = row.Content;
                    if (entity != null)
                    {
                        obj["content_id"]  = entity.Id;
                        obj["lang"]        = entity.Lang;
                        obj["description"] = entity.Description;
                        obj["title"]       = entity.Title;
                    }
                }
                break;

                case PostQueryProjection.CONTENT_CONTENT:
                {
                    var entity = row.Content;
                    if (entity != null)
                    {
                        obj["content"] = entity.Content;
                    }
                }
                break;

                case PostQueryProjection.OWNER:
                {
                    var entity = row.Owner;
                    obj["owner"] = new
                    {
                        id   = entity.Id,
                        code = entity.Code,
                        name = entity.Name,
                    };
                }
                break;
                }
            }
            return(obj);
        }