public async Task <IActionResult> GetClientesNoVinculados([FromBody] ClientesByDistRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var dist = _context.Distribuidor.Where(d => d.id == request.DistId).FirstOrDefault();

            if (dist == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "El distribuidor especificado no existe."
                }));
            }

            var clientes = await _context.ClienteDistribuidor
                           .Include(item => item.Cliente)
                           .Where(cd => cd.DistribuidorId != dist.id)
                           .ToListAsync();

            return(Ok(_converterHelper.ToClientsResponse(clientes)));
        }
Пример #2
0
        public async Task <Response> GetClientsByDist(
            string urlBase,
            string servicePrefix,
            string controller,
            ClientesByDistRequest request)
        {
            try
            {
                string        requestString = JsonConvert.SerializeObject(request);
                StringContent content       = new StringContent(requestString, Encoding.UTF8, "application/json");
                HttpClient    client        = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string result = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = result,
                    });
                }

                List <ClieResponse> clienteResponse = JsonConvert.DeserializeObject <List <ClieResponse> >(result);
                return(new Response
                {
                    IsSuccess = true,
                    Result = clienteResponse
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }