示例#1
0
        public async Task <IActionResult> DeclineRequest(Guid receiverId, Guid senderId, byte requestTypeId)
        {
            var tkn = Request.Headers["Authorization"];

            if (!_authService.AuthorizeSelf(tkn, receiverId))
            {
                return(Unauthorized());
            }

            var request = await _requestsRepository.GetRequestByUserIdsAndType(receiverId, senderId,
                                                                               (RequestType)requestTypeId);

            if (request == null)
            {
                return(BadRequest(new Error("invalid_request", "There is no pending request.")));
            }

            await _requestsService.DeclineRequest(request);

            return(Ok());
        }
示例#2
0
        public async Task <IList <Error> > ValidateAcceptRequest(Request request)
        {
            var errors = new List <Error>();

            var req = await _requestsRepository.GetRequestByUserIdsAndType(request);

            if (req == null)
            {
                errors.Add(new Error("invalid_request", "There is no pending request."));
            }

            switch (request.RequestType)
            {
            case RequestType.Friend:
                if (await _relationshipsService.AreAlreadyFriends(request.SenderId, request.ReceiverId))
                {
                    errors.Add(new Error("invalid_request", "You are already connected."));
                }
                break;
            }

            return(errors);
        }
示例#3
0
 public async Task <bool> IsRequestAlreadySent(Request request)
 => await _requestsRepository.GetRequestByUserIdsAndType(request) != null;