public async Task <ActionResult <ConfigurationVendor> > Update([FromBody] ConfigurationVendor _ConfigurationVendor)
        {
            ConfigurationVendor _ConfigurationVendorq = _ConfigurationVendor;

            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _ConfigurationVendorq = await(from c in _context.ConfigurationVendor
                                                      .Where(q => q.ConfigurationVendorId == _ConfigurationVendor.ConfigurationVendorId)
                                                      select c
                                                      ).FirstOrDefaultAsync();

                        _context.Entry(_ConfigurationVendorq).CurrentValues.SetValues((_ConfigurationVendor));

                        //_context.Alert.Update(_Alertq);
                        await _context.SaveChangesAsync();

                        BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora
                        {
                            IdOperacion  = _ConfigurationVendor.ConfigurationVendorId,
                            DocType      = "ConfigurationVendor",
                            ClaseInicial =
                                Newtonsoft.Json.JsonConvert.SerializeObject(_ConfigurationVendorq, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_ConfigurationVendor, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            Accion              = "Actualizar",
                            FechaCreacion       = DateTime.Now,
                            FechaModificacion   = DateTime.Now,
                            UsuarioCreacion     = _ConfigurationVendor.CreatedUser,
                            UsuarioModificacion = _ConfigurationVendor.ModifiedUser,
                            UsuarioEjecucion    = _ConfigurationVendor.ModifiedUser,
                        });

                        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(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_ConfigurationVendorq)));
        }
        public async Task <ActionResult <ConfigurationVendor> > Insert([FromBody] ConfigurationVendor _ConfigurationVendor)
        {
            ConfigurationVendor _ConfigurationVendorq = new ConfigurationVendor();

            // Alert _Alertq = new Alert();
            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _ConfigurationVendorq = _ConfigurationVendor;
                        _context.ConfigurationVendor.Add(_ConfigurationVendorq);
                        await _context.SaveChangesAsync();

                        BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora
                        {
                            IdOperacion  = _ConfigurationVendor.ConfigurationVendorId,
                            DocType      = "ConfigurationVendor",
                            ClaseInicial =
                                Newtonsoft.Json.JsonConvert.SerializeObject(_ConfigurationVendor, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            Accion              = "Insertar",
                            FechaCreacion       = DateTime.Now,
                            FechaModificacion   = DateTime.Now,
                            UsuarioCreacion     = _ConfigurationVendor.CreatedUser,
                            UsuarioModificacion = _ConfigurationVendor.ModifiedUser,
                            UsuarioEjecucion    = _ConfigurationVendor.ModifiedUser,
                        });

                        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(await Task.Run(() => Ok(_ConfigurationVendorq)));
        }
        public async Task <IActionResult> GetConfigurationVendorById(Int64 ConfigurationVendorId)
        {
            ConfigurationVendor Items = new ConfigurationVendor();

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


            return(await Task.Run(() => Ok(Items)));
        }
        public async Task <IActionResult> GetConfigurationVendorActive()

        {
            ConfigurationVendor Items = new ConfigurationVendor();

            try
            {
                Items = await _context.ConfigurationVendor.Where(p => p.Estado == "Activo").FirstOrDefaultAsync();
            }
            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(Items)));
        }
        public async Task <IActionResult> Delete([FromBody] ConfigurationVendor _ConfigurationVendor)
        {
            ConfigurationVendor _ConfigurationVendorq = new ConfigurationVendor();

            try
            {
                _ConfigurationVendorq = _context.ConfigurationVendor
                                        .Where(x => x.ConfigurationVendorId == (Int64)_ConfigurationVendor.ConfigurationVendorId)
                                        .FirstOrDefault();

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

            return(await Task.Run(() => Ok(_ConfigurationVendorq)));
        }