public void Initialize() { using (BombasContext context = new BombasContext()) { int currentVersion = 0; if (context.SchemaInfoes.Count() > 0) { currentVersion = context.SchemaInfoes.Max(x => x.Version); } BombasContextHelper mmSqliteHelper = new BombasContextHelper(); while (currentVersion < RequiredDatabaseVersion) { currentVersion++; foreach (string migration in mmSqliteHelper.Migrations[currentVersion]) { context.Database.ExecuteSqlCommand(migration); } context.SchemaInfoes.Add(new SchemaInfo() { Version = currentVersion }); context.SaveChanges(); } } }
private Preco fetchPreco() { Preco preco; using (var context = new BombasContext()) { DateTime data = DateTime.Now; preco = context.Precos.Where(p => p.data == data.ToShortDateString()).FirstOrDefault(); } return(preco); }
private void definePreco_Click(object sender, EventArgs e) { if (precoGasolina.Text.Length > 0) { using (var context = new BombasContext()) { Preco novoPreco = new Preco(); DateTime data = DateTime.Now; novoPreco.valor = Convert.ToDecimal(precoGasolina.Text); novoPreco.data = data.ToString(); context.Precos.Add(novoPreco); context.SaveChanges(); } } }
private void salvaVenda(string valor, int bombaId) { using (var context = new BombasContext()) { Preco preco = fetchPreco(); Bomba bomba = context.Bombas.Find(bombaId); Venda venda = new Venda(); venda.bomba = bomba; venda.preco = preco; venda.litros = Convert.ToDecimal(valor) / preco.valor; context.Vendas.Add(venda); context.SaveChanges(); } }
public void Initialize() { using (BombasContext context = new BombasContext()) { int currentVersion = 0; if (context.SchemaInfoes.Count() > 0) currentVersion = context.SchemaInfoes.Max(x => x.Version); BombasContextHelper mmSqliteHelper = new BombasContextHelper(); while (currentVersion < RequiredDatabaseVersion) { currentVersion++; foreach (string migration in mmSqliteHelper.Migrations[currentVersion]) { context.Database.ExecuteSqlCommand(migration); } context.SchemaInfoes.Add(new SchemaInfo() { Version = currentVersion }); context.SaveChanges(); } } }
private Preco fetchPreco() { Preco preco; using (var context = new BombasContext()) { DateTime data = DateTime.Now; preco = context.Precos.Where(p => p.data == data.ToShortDateString()).FirstOrDefault(); } return preco; }