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; } }
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()); }
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); }
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; } }