コード例 #1
0
        public async Task <BaseResponse <ShowTimelineResponse> > Handle(ShowTimelineQuery request, CancellationToken cancellationToken)
        {
            var  response         = new BaseResponse <ShowTimelineResponse>();
            bool isMatch          = false;
            bool isPendingRequest = false;
            ShowTimelineResponse showTimelineResponse = new ();

            // Busca se os usuários são amigos
            var matchesQuery = _dbContext.Matches.Where(m => m.IdUser == request.UserId);

            if (matchesQuery.Any())
            {
                var matches = matchesQuery.ToList();
                foreach (var m in matches)
                {
                    if (m.IdAmigo == request.IdAmigo)
                    {
                        isMatch = true;
                    }
                }
            }

            // Busca se existe um pedido pendente entre os usuários
            var PedidoPendenteUser = _dbContext.PedidosMatch
                                     .Where(p => p.IdUserAprovador == request.IdAmigo)
                                     .Where(p => p.IdUserSolicitante == request.UserId)
                                     .Where(p => p.IdStatusSolicitacao.Id == 1);

            var PedidoPendenteAmigo = _dbContext.PedidosMatch
                                      .Where(p => p.IdUserAprovador == request.UserId)
                                      .Where(p => p.IdUserSolicitante == request.IdAmigo)
                                      .Where(p => p.IdStatusSolicitacao.Id == 1);

            if (PedidoPendenteUser.Any() || PedidoPendenteAmigo.Any())
            {
                isPendingRequest = true;
            }

            // Se não houver match nem pedido pendente então é exibido na timeline
            if (isMatch == false && isPendingRequest == false)
            {
                showTimelineResponse.IdAmigo = request.IdAmigo;
            }

            response.SetIsOk(showTimelineResponse);

            return(response);
        }
コード例 #2
0
        public async Task <IActionResult> ShowTimeline(Guid id, [FromBody] ShowTimelineRequest idAmigo)
        {
            List <ShowTimelineResponse> showTimelineResponse = new();
            var response = new BaseResponse <List <ShowTimelineResponse> >();

            foreach (var a in idAmigo.idAmigos)
            {
                var query  = new ShowTimelineQuery(id, a.IdAmigo);
                var result = await Mediator.Send(query);

                Guid guid = new("00000000-0000-0000-0000-000000000000");

                if (!result.Data.IdAmigo.Equals(guid))
                {
                    showTimelineResponse.Add(result.Data);
                }
            }

            response.SetIsOk(showTimelineResponse);

            return(await ResponseBase(response));
        }