Beispiel #1
0
        public async Task <BaseResponse <InterestComparsionResponse> > Handle(InterestComparsionQuery request, CancellationToken cancellationToken)
        {
            var usersInterestDbSet = _applicationDbContext.UserInterests;

            var userInterestsList = await(from userInterests in usersInterestDbSet
                                          where userInterests.UserId == request.UserId
                                          select userInterests.InterestId).ToListAsync(cancellationToken);

            var userInterestsListFriends = await(from userInterests in usersInterestDbSet
                                                 where  userInterestsList.Contains(userInterests.InterestId) && request.IdAmigos.IdAmigos.Contains(userInterests.UserId)
                                                 select userInterests).ToListAsync(cancellationToken);

            var interestComparisonResponses = new InterestComparsionResponse();

            foreach (var userInterestsListFriend in userInterestsListFriends)
            {
                if (interestComparisonResponses.IdAmigos.Contains(userInterestsListFriend.UserId) || userInterestsListFriend.UserId == request.UserId)
                {
                    continue;
                }
                interestComparisonResponses.IdAmigos.Add(userInterestsListFriend.UserId);
            }

            var response = new BaseResponse <InterestComparsionResponse>();

            response.SetIsOk(interestComparisonResponses);

            return(response);
        }
        public async Task <IActionResult> InterestComparsion(Guid id, [FromBody] InterestComparsionResponse request)
        {
            var query  = new InterestComparsionQuery(id, request);
            var result = await Mediator.Send(query);

            return(await ResponseBase(result));
        }