Пример #1
0
        private GraphChangeStatus addFriend(GDID gNode, GDID gFriendNode, bool?approve, FriendshipRequestDirection direction)
        {
            GraphChangeStatus result;
            var ctx = ForNode(gNode);
            var row = ctx.LoadRow(Queries.FindOneFriendByNodeAndFriend <FriendRow>(gNode, gFriendNode));

            if (row != null)
            {
                if (approve == null)
                {
                    return(GraphChangeStatus.Updated);
                }
                row.Status      = approve.Value ? GSFriendStatus.APPROVED : GSFriendStatus.DENIED;
                row.Status_Date = App.TimeSource.UTCNow;
                ctx.Update(row);
                result = GraphChangeStatus.Updated;
            }
            else
            {
                row = new FriendRow(true)
                {
                    G_Owner      = gNode,
                    G_Friend     = gFriendNode,
                    Status_Date  = App.TimeSource.UTCNow,
                    Status       = approve != null && approve.Value ? GSFriendStatus.APPROVED: GSFriendStatus.PENDING,
                    Visibility   = GSFriendVisibility.FRIENDS,
                    Request_Date = App.TimeSource.UTCNow,
                    Direction    = GSFriendshipRequestDirection.ToDomainString(direction)
                };
                ctx.Insert(row);
                result = GraphChangeStatus.Added;
            }
            return(result);
        }
Пример #2
0
        protected virtual IEnumerable <FriendConnection> DoGetFriendConnections(FriendQuery query, ICacheParams cacheParams = null)
        {
            var rows = ForNode(query.G_Node).LoadEnumerable(Queries.FindFriends <FriendRow>(query));

            foreach (var row in rows)
            {
                var friendNode = DoGetNode(row.G_Friend, cacheParams);
                foreach (var graphNode in GraphHost.FilterByOriginQuery(new[] { friendNode }, query.OriginQuery))
                {
                    yield return(new FriendConnection(graphNode,
                                                      row.Request_Date,
                                                      FriendStatus.Approved.Equals(GSFriendStatus.ToFriendStatus(row.Status))
              ? (DateTime?)row.Status_Date
              : null,
                                                      GSFriendshipRequestDirection.ToFriendshipRequestDirection(row.Direction),
                                                      GSFriendVisibility.ToFriendVisibility(row.Visibility),
                                                      row.Lists));
                }
            }
        }