/// <inheritdoc/> public async Task <ValidState> ValidateNodeAsync(TreeNode node, ValidState state) { var id = new EntityId(node.Id.System, node.Id.Type, Constraints.SCH_GNODE, node.G_Parent.ToString()); var parent = await this.GetNodeInfoAsync(id, node.StartUtc, CacheParams.ReadFreshWriteSec(60)).ConfigureAwait(false); if (parent == null) { state = new ValidState(state, new FieldValidationException(node, nameof(node.G_Parent), "Parent node `{0}` is not found as of the requested StartUtc of `{1}`. Create parent node first".Args(id, node.StartUtc))); } return(state); }
public virtual IEnumerable <Comment> Fetch(CommentQuery query) { var start = query.BlockIndex * CommentQuery.COMMENT_BLOCK_SIZE; var comments = Cache.FetchThrough <CommentQuery, IEnumerable <Comment> >(query, SocialConsts.GS_COMMENT_BLOCK_TBL, CacheParams.ReadFreshWriteSec(0), // todo TO DISCUSS commQry => { var rows = new List <CommentRow>(); var qryVolumes = Queries.FindCommentVolumes <CommentVolumeRow>(query.G_TargetNode, query.Dimension, MaxLastCommentVolumes, query.AsOfDate); var volumes = ForNode(query.G_TargetNode).LoadEnumerable(qryVolumes); foreach (var volume in volumes) { var qryComments = Queries.FindComments <CommentRow>(query.G_TargetNode, query.Dimension, true); var loadRows = ForComment(volume.G_CommentVolume).LoadEnumerable(qryComments); rows.AddRange(loadRows); } IEnumerable <CommentRow> orderedRows = null; switch (query.OrderType) { case CommentOrderType.ByDate: if (query.Ascending) { orderedRows = rows.OrderBy(row => row.Create_Date); } else { orderedRows = rows.OrderByDescending(row => row.Create_Date); } break; case CommentOrderType.ByPositive: orderedRows = rows.OrderBy(row => row.Rating) .ThenByDescending(row => row.Create_Date); break; case CommentOrderType.ByNegative: orderedRows = rows.OrderByDescending(row => row.Rating) .ThenByDescending(row => row.Create_Date); break; case CommentOrderType.ByPopular: if (query.Ascending) { orderedRows = rows.OrderBy(row => row.Like + row.Dislike) .ThenByDescending(row => row.Create_Date); } else { orderedRows = rows.OrderByDescending(row => row.Like + row.Dislike) .ThenByDescending(row => row.Create_Date); } break; case CommentOrderType.ByUsefull: if (query.Ascending) { orderedRows = rows.OrderBy(row => row.Like - row.Dislike) .ThenByDescending(row => row.Create_Date); } else { orderedRows = rows.OrderByDescending(row => row.Like - row.Dislike) .ThenByDescending(row => row.Create_Date); } break; default: orderedRows = rows.OrderByDescending(row => row.Create_Date); break; } return(orderedRows.Skip(start) .Take(CommentQuery.COMMENT_BLOCK_SIZE) .Select(RowToComment).ToArray()); }); return(comments); }