public ActionResult Index(List <PedidoIndexViewModel> model)
        {
            var pedidos    = _pedidoRepo.ListPedido();
            var viewModels = new List <PedidoIndexViewModel>();

            pedidos.ForEach(p =>
            {
                var viewModel = new PedidoIndexViewModel();

                viewModel.Pedido        = p;
                viewModel.Cliente       = _clienteRepo.ClienteById(p.IdCliente);
                viewModel.Transportador = _transportadorRepo.TransportadorById(p.IdTransport);
                viewModel.Usuario       = _usuarioRepo.UsuarioById(p.IdUsuario);

                viewModels.Add(viewModel);
            });
            if (model.Count == 0)
            {
                model = viewModels;
            }

            return(PartialView("Index", model));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            PedidoIndexViewModel pedidoIndexViewModel;
            HttpClient           httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(configurations.Configuration["ServicesReference:0:PdsControleVendasApi"].ToString());

            var response = await httpClient.GetAsync("/v1/pedido");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var content = await response.Content.ReadAsStringAsync();

                var statusPedidos = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Pedido> >(content);

                pedidoIndexViewModel = new PedidoIndexViewModel(statusPedidos);
            }
            else
            {
                pedidoIndexViewModel = new PedidoIndexViewModel();
            }

            return(View(pedidoIndexViewModel));
        }