예제 #1
0
 public void UpdateProduct(Product product)
 {
     using (var context = new MotoContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #2
0
 public void SaveProduct(Product product)
 {
     using (var context = new MotoContext()) //عبارة الاتصال
     {
         context.Products.Add(product);      //استخدمنا تابع الاضافه وضفناه
         context.SaveChanges();              // حفظنا التغييرات
     }
 }
예제 #3
0
        public void DeleteCategory(int ID)
        {
            using (var context = new MotoContext())
            {
                var category = context.Categories.Find(ID);

                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
예제 #4
0
        public void DeleteProduct(int ID)
        {
            using (var context = new MotoContext())
            {
                var product = context.Products.Find(ID);

                context.Products.Remove(product);
                context.SaveChanges();
            }
        }
예제 #5
0
        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();
            }
        }
예제 #6
0
 public BrandRepository(MotoContext context)
 {
     _context = context;
 }
예제 #7
0
 public CategoryRepository(MotoContext context)
 {
     _context = context;
 }
예제 #8
0
 public Repositorio(MotoContext contexto)
 {
     _contexto = contexto;
 }
예제 #9
0
 public UnitOfWork()
 {
     _context = new MotoContext();
 }
예제 #10
0
 public EngineRepository(MotoContext context)
 {
     _context = context;
 }
 public MotorcycleRepository(MotoContext context)
 {
     _context = context;
 }