Esempio n. 1
0
        public async Task <ActionResult <Boleto_Ent> > Update([FromBody] Boleto_Ent _Boleto_Ent)
        {
            Boleto_Ent _Boleto_Entq = _Boleto_Ent;

            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _Boleto_Entq = await(from c in _context.Boleto_Ent
                                             .Where(q => q.clave_e == _Boleto_Ent.clave_e)
                                             select c
                                             ).FirstOrDefaultAsync();

                        _context.Entry(_Boleto_Entq).CurrentValues.SetValues((_Boleto_Ent));

                        //_context.Boleto_Ent.Update(_Boleto_Entq);
                        await _context.SaveChangesAsync();

                        BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora
                        {
                            IdOperacion  = _Boleto_Ent.clave_e,
                            DocType      = "Boleto_Ent",
                            ClaseInicial =
                                Newtonsoft.Json.JsonConvert.SerializeObject(_Boleto_Ent, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_Boleto_Ent, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            Accion            = "Insert",
                            FechaCreacion     = DateTime.Now,
                            FechaModificacion = DateTime.Now,
                            //UsuarioCreacion = _Boleto_Ent.UsuarioCreacion,
                            //UsuarioModificacion = _Boleto_Ent.UsuarioModificacion,
                            //UsuarioEjecucion = _Boleto_Ent.UsuarioModificacion,
                        });

                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                        throw ex;
                        // return BadRequest($"Ocurrio un error:{ex.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(Ok(_Boleto_Entq));
        }
Esempio n. 2
0
        public async Task <ActionResult <Int64> > GetBoleto_EntCount()
        {
            // List<Boleto_Ent> Items = new List<Boleto_Ent>();
            Boleto_Ent _Boleto_Ent = new Boleto_Ent();
            Int64      Total       = 0;

            try
            {
                Total = await _context.Boleto_Ent.CountAsync();

                //Items = await _context.Boleto_Ent.ToListAsync();
                //_Boleto_Ent = await _context.Boleto_Ent.FromSql("select  count(clave_e) clave_e  from Boleto_Ent ").FirstOrDefaultAsync();
                //_Boleto_Ent = await _context.Query<Boleto_Ent>()
                // .FromSql($"SELECT count(clave_e) as clave_e FROM dbo.Boleto_Ent ")
                //  .AsNoTracking()
                //  .FirstOrDefaultAsync();

                // Total = _Boleto_Ent.clave_e;
                //Items = await _context.Boleto_Ent.ToListAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            //  int Count = Items.Count();
            return(await Task.Run(() => Ok(Total)));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetBoleto_EntById(Int64 Boleto_EntId)
        {
            Boleto_Ent Items = new Boleto_Ent();

            try
            {
                Items = await _context.Boleto_Ent.Include(q => q.Boleto_Sal).Where(q => q.clave_e == Boleto_EntId).FirstOrDefaultAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }


            return(Ok(Items));
        }
Esempio n. 4
0
        public async Task <IActionResult> Delete([FromBody] Boleto_Ent _Boleto_Ent)
        {
            Boleto_Ent _Boleto_Entq = new Boleto_Ent();

            try
            {
                _Boleto_Entq = _context.Boleto_Ent
                               .Where(x => x.clave_e == (Int64)_Boleto_Ent.clave_e)
                               .FirstOrDefault();

                _context.Boleto_Ent.Remove(_Boleto_Entq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(Ok(_Boleto_Entq));
        }