Exemple #1
0
 public async Task <bool> Actualizar(Orden entity)
 {
     _dbSet.Attach(entity);
     _contexto.Entry(entity).State = EntityState.Modified;
     try
     {
         return(await _contexto.SaveChangesAsync() > 0 ? true : false);
     }
     catch (Exception excepcion)
     {
         _logger.LogError($"Error en {nameof(Actualizar)}: " + excepcion.Message);
     }
     return(false);
 }
Exemple #2
0
        public async Task <Perfil> Agregar(Perfil entity)
        {
            _dbSet.Add(entity);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error en {nameof(Agregar)}: " + ex.Message);
                return(null);
            }
            return(entity);
        }
Exemple #3
0
        public async Task <bool> Actualizar(Producto producto)
        {
            var productBd = await ObtenerProductoAsync(producto.Id);

            productBd.Nombre = producto.Nombre;
            productBd.Precio = producto.Precio;
            //_contexto.Productos.Attach(producto);
            //_contexto.Entry(producto).State = EntityState.Modified;
            try
            {
                return(await _contexto.SaveChangesAsync() > 0 ? true : false);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Update Produt Error {nameof(Actualizar)}: ${ex.Message}");
            }
            return(false);
        }
        public async Task <Producto> Agregar(Producto producto)
        {
            producto.Estatus       = EstatusProducto.Activo;
            producto.FechaRegistro = DateTime.Now;

            _context.Productos.Add(producto);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error en {nameof(Agregar)}: {ex.Message}");
                return(null);
            }
            return(producto);
        }
        public async Task <bool> Actualizar(Usuario entity)
        {
            var usuarioDb = await _dbSet.FirstOrDefaultAsync(u => u.Id == entity.Id);

            if (usuarioDb == null)
            {
                _logger.LogError($"Error en {nameof(Actualizar)}: No existe el usuario con Id: {entity.Id}");
                return(false);
            }

            usuarioDb.Nombre    = entity.Nombre;
            usuarioDb.Apellidos = entity.Apellidos;
            usuarioDb.Email     = entity.Email;
            try
            {
                return(await _contexto.SaveChangesAsync() > 0 ? true : false);
            }
            catch (Exception excepcion)
            {
                _logger.LogError($"Error en {nameof(Actualizar)}: " + excepcion.Message);
            }
            return(false);
        }
Exemple #6
0
 public async Task <int> CompleteAsync()
 {
     return(await _dbContext.SaveChangesAsync());
 }