public bool Inserir(Gasto gasto) { using (var db = new GastosContext()) { if (db.Database.Connection != null) { db.Gastos.Add(gasto); db.SaveChanges(); return(true); } return(false); } }
public bool Excluir(int id) { using (GastosContext db = new GastosContext()) { if (db.Database.Connection != null) { Gasto gasto = db.Gastos.FirstOrDefault(a => a.Id == id); db.Gastos.Remove(gasto); db.SaveChanges(); return(true); } return(false); } }
public bool Atualizar(Gasto gasto) { using (GastosContext db = new GastosContext()) { if (db.Database.Connection != null) { db.Gastos.Attach(gasto); db.Entry(gasto).State = EntityState.Modified; db.SaveChanges(); return(true); } return(false); } }