public async Task <IActionResult> Create([Bind("CodEmpresa,IdCuenta,NumSecuencia,TipTransaccion,SubtipTransac,FecTransaccion,CodMoneda,CodSistema,CodCliente,MonMovimiento,TipCambio,AsientoContable,Beneficiario,IndEstado,Observaciones,NumDocumento,IndEnvCajas,CodCajero,CtaExterna,NumReferencia,TransactionTime")] BaTranDiario baTranDiario)
        {
            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseurl);

                    var myContent   = JsonConvert.SerializeObject(baTranDiario);
                    var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                    var byteContent = new ByteArrayContent(buffer);
                    byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    var postTask = client.PostAsync("api/BaTranDiario", byteContent).Result;

                    var result = postTask;
                    if (result.IsSuccessStatusCode)
                    {
                        //return RedirectToAction("Index");
                        return(RedirectToAction(nameof(Index)));
                    }
                }
                ModelState.AddModelError(string.Empty, "Server Error, Please contact administrator");
            }
            return(View(baTranDiario));
        }
        public async Task <ActionResult <data.BaTranDiario> > GetBaTranDiario(string id)
        {
            var batrandiario = new BaTranDiario(_context).GetOneById(id);

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

            return(batrandiario);
        }
        public async Task <ActionResult <data.BaTranDiario> > DeleteBaTranDiario(string id)
        {
            var batrandiario = new BaTranDiario(_context).GetOneById(id);

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

            new BaTranDiario(_context).Delete(batrandiario);
            await _context.SaveChangesAsync();

            return(batrandiario);
        }
        //private bool BaTranDiarioExists(string id)
        //{
        //    return _context.BaTranDiario.Any(e => e.CodEmpresa == id);
        //}

        private async Task <BaTranDiario> GetOneById(int?id, BaTranDiario aux)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage res = await client.GetAsync("api/BaTranDiario/" + id);

                if (res.IsSuccessStatusCode)
                {
                    var auxRes = res.Content.ReadAsStringAsync().Result;

                    aux = JsonConvert.DeserializeObject <BaTranDiario>(auxRes);
                }
            }

            return(aux);
        }