public async Task <JsonDefaultResponse> Handle(IncomingsByUserId request, CancellationToken cancellationToken)
        {
            var userHasPerson = await _context.UserHasPerson
                                .Where(uhp => uhp.UserId == request.UserId)
                                .SingleOrDefaultAsync();

            if (userHasPerson == null)
            {
                return new JsonDefaultResponse
                       {
                           Success = false,
                           Message = "O usuário informado não foi encontrado"
                       }
            }
            ;

            var incomings = await _context.Incoming
                            .Where(i => i.PersonId == userHasPerson.PersonId)
                            .Where(i => i.Status == Status.Active)
                            .Select(i => IncomingsByUserIdModel.Create(i))
                            .ToListAsync();

            return(new JsonDefaultResponse
            {
                Success = true,
                Payload = incomings
            });
        }
    }
Esempio n. 2
0
        public async Task <GetIncomingsByUserIdResponse> Handle(GetIncomingsByUserIdRequest request, CancellationToken cancellationToken)
        {
            if (await UserNotFound(request.UserId))
            {
                return(FailResponse($"O usuário com id {request.UserId} não foi encontrado", 400));
            }

            var incomings = await _context.Incoming
                            .Where(i => i.PersonId == userHasPerson.PersonId && i.Status == Status.Active)
                            .Select(i => IncomingsByUserIdModel.Create(i))
                            .ToListAsync();

            return(new GetIncomingsByUserIdResponse {
                Incomings = incomings
            });
        }