Exemplo n.º 1
0
        private Task ResolveSenders(AnyTimerInputType args, AnyTimer anyTimer,
                                    ResolveFieldContext <object> context)
        {
            return(Task.WhenAll(args.Senders.Select(async senderInput =>
            {
                if (anyTimer.ReceiverId.Equals(senderInput.User))
                {
                    context.Error(GraphQLErrors.ReceiverSameAsSender);
                    return;
                }

                if (!senderInput.User.Equals(anyTimer.CreatorId))
                {
                    var sender = await context.UserRecord(senderInput.User);
                    if (sender == null)
                    {
                        context.Error(GraphQLErrors.UnknownUser(senderInput.User));
                        return;
                    }

                    if ((await _friendRepository.ByUsers(anyTimer.CreatorId, sender.Uid))?.Status !=
                        FriendRequestStatus.Accepted)
                    {
                        context.Error(GraphQLErrors.NotFriends(sender.Uid));
                        return;
                    }
                }

                anyTimer.Senders.Add(new AnyTimerSender
                {
                    SenderId = senderInput.User,
                    Amount = senderInput.Amount,
                    AnyTimerId = anyTimer.Id
                });
            })));
        }