// GET: Pedidos/Send
        public async Task <IActionResult> Send(string id)
        {
            var pedido = await _context.Pedidos.FirstOrDefaultAsync(i => i.InvoiceNumber == id);

            if (pedido != null)
            {
                return(Forbid());
            }
            var invoice = await _api.GetInvoice("http://facturacion-utn-amazon.herokuapp.com", "/api/invoice", id);

            if (invoice == null)
            {
                return(NotFound());
            }

            var email = User.Identity.Name;

            if (invoice.user_client.email != email)
            {
                return(Forbid());
            }

            var seguimiento = new SeguimientoVM
            {
                InvoiceNumber = id,
                PedTotal      = decimal.Parse(invoice.total)
            };

            return(View(seguimiento));
        }
        public async Task <IActionResult> Send(string id, SeguimientoVM seguimiento)
        {
            if (ModelState.IsValid)
            {
                var invoice = await _api.GetInvoice("http://facturacion-utn-amazon.herokuapp.com", "/api/invoice", id);

                if (invoice == null)
                {
                    return(NotFound());
                }

                var email = User.Identity.Name;

                if (invoice.user_client.email != email)
                {
                    return(Forbid());
                }

                try
                {
                    var now    = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.Local);
                    var tipoT  = seguimiento.PedTipoEnvio.Equals("T");
                    var regalo = seguimiento.PedRegalo.Equals("S");

                    var extra = 0;
                    if (!tipoT)
                    {
                        extra = 5;
                    }

                    if (regalo)
                    {
                        extra += 10;
                    }

                    var pedido = new Pedidos
                    {
                        InvoiceNumber    = id,
                        ClienteEmail     = email,
                        PedTotal         = decimal.Parse(invoice.total),
                        PedFechaEnvio    = now,
                        PedFase          = 'P',
                        PedLugarOrigen   = seguimiento.PedLugarOrigen,
                        PedLugarDestino  = seguimiento.PedLugarDestino,
                        PedEnvioEstandar = tipoT,
                        PedCostoExtra    = extra,
                        PedRegalo        = regalo,
                        PedTarjeta       = seguimiento.PedTarjeta
                    };

                    _context.Add(pedido);
                    await _context.SaveChangesAsync();

                    _flashMessage.Confirmation("Pedido enviado.");

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            seguimiento.InvoiceNumber = id;

            return(View(seguimiento));
        }