Beispiel #1
0
        public virtual void Add(Model item)
        {
            try
            {
                using (var db = new escuelapsdelsurContext())
                {
                    db.Set <Model>().Add(item);
                    db.SaveChanges();

                    _logger.LogInformation("Crear " + typeof(Model).Name + "--> Ok");
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
                throw ex;
            }
        }
Beispiel #2
0
 public virtual IEnumerable <Model> GetAll()
 {
     _list.Clear();
     try
     {
         using (var db = new escuelapsdelsurContext())
         {
             foreach (var item in db.Set <Model>())
             {
                 _list.Add(item);
             }
         }
         _logger.LogInformation("Buscar " + typeof(Model).Name + " --> OK");
     }
     catch (System.Exception ex)
     {
         _logger.LogError(ex.Message);
     }
     return(_list.AsReadOnly());
 }
Beispiel #3
0
        public virtual Model Find(params Object[] KeyValues)
        {
            //return default(Model);

            Model ItemBuscado = null;

            try
            {
                using (var db = new escuelapsdelsurContext())
                {
                    ItemBuscado = db.Set <Model>().Find(KeyValues);
                    _logger.LogInformation("Buscar " + typeof(Model).Name + " --> OK");
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
                throw ex;
            }
            return(ItemBuscado);
        }
Beispiel #4
0
 public virtual void Remove(params Object[] KeyValues)
 {
     try
     {
         using (var db = new escuelapsdelsurContext())
         {
             var ItemBuscado = db.Set <Model>().Find(KeyValues);
             if (ItemBuscado != null)                     //Implementa Idempotencia.
             {
                 db.Remove(ItemBuscado);
                 db.SaveChanges();
             }
             _logger.LogInformation("Eliminar " + typeof(Model).Name + " --> OK");
         }
     }
     catch (System.Exception ex)
     {
         _logger.LogError(ex.Message);
         throw ex;
     }
 }