public void UpdateProduct(Product product) { using (var context = new MotoContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void SaveProduct(Product product) { using (var context = new MotoContext()) //عبارة الاتصال { context.Products.Add(product); //استخدمنا تابع الاضافه وضفناه context.SaveChanges(); // حفظنا التغييرات } }
public void DeleteCategory(int ID) { using (var context = new MotoContext()) { var category = context.Categories.Find(ID); context.Categories.Remove(category); context.SaveChanges(); } }
public void DeleteProduct(int ID) { using (var context = new MotoContext()) { var product = context.Products.Find(ID); context.Products.Remove(product); context.SaveChanges(); } }
private void btnAdd_Click(object sender, EventArgs e) { if (sender == btnAdd) { clienteBindingSource.Add(new Cliente()); clienteBindingSource.MoveLast(); } if (clienteBindingSource.Current == null) { return; } using (var cad = new FrmCadastroCliente(clienteBindingSource.Current as Cliente)) { if (cad.ShowDialog() == DialogResult.OK) { var cliente = clienteBindingSource.Current as Cliente; if (cliente == null) { return; } using (var db = new MotoContext()) { if (db.Entry <Cliente>(cliente).State == EntityState.Detached) { db.Set <Cliente>().Attach(cliente); } db.Entry <Cliente>(cliente).State = cliente.Id == 0 ? EntityState.Added : EntityState.Modified; if (db.SaveChanges() > 0) { datagrdCliente.Refresh(); MessageBox.Show($@"Cliente {cliente.Nome} gravado com sucesso!.", @"Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show($@"Cliente {cliente.Nome} não pode ser gravado !.", @"Informação", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } cad.ShowDialog(); } }
public BrandRepository(MotoContext context) { _context = context; }
public CategoryRepository(MotoContext context) { _context = context; }
public Repositorio(MotoContext contexto) { _contexto = contexto; }
public UnitOfWork() { _context = new MotoContext(); }
public EngineRepository(MotoContext context) { _context = context; }
public MotorcycleRepository(MotoContext context) { _context = context; }