private void OnDeleteSale() { Sale saleSelected; using (MFSContext context = new MFSContext()) { saleSelected = context.Sales.Find(SelectedSale.SaleID); saleSelected.Remove = 1; ICollection <SaleDetail> orderDetail = saleSelected.SaleDetails; if (orderDetail != null) { foreach (var od in orderDetail) { od.Remove = 1; context.Entry(od).State = System.Data.Entity.EntityState.Modified; } } context.Entry(saleSelected).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); MessageBox.Show("Venta eliminada correctamente"); } }
private void OnUpdateOrder() { using (MFSContext context = new MFSContext()) { Order order = new Order() { OrderId = 0 }; int isNewOrder = 0; if (SelectedOrder.OrderID != 0) { isNewOrder = 1; order = context.Orders.Include(o => o.User).Include(o => o.Suplier).Single(o => o.OrderId == SelectedOrder.OrderID); } order.User = context.Users.Find(UserLogin.Id); order.Date = SelectedOrder.Date; order.Suplier = context.Supliers.Find(SelectedOrder.SuplierId); order.CodOrder = SelectedOrder.CodOrder; context.Entry(order).State = SelectedOrder.OrderID == 0 ? EntityState.Added : EntityState.Modified; context.SaveChanges(); LoadOrder(); //Nueva order if (isNewOrder == 0) { OrderDetailView orderDetailView = new OrderDetailView(); orderDetailView.OrderId.Text = Convert.ToString(order.OrderId); orderDetailView.ShowDialog(); } } }
private void OnUpdateProduct() { if (!ProductValidation()) { return; } using (MFSContext context = new MFSContext()) { Product product = new Product(); if (SelectedProduct.Id != 0) { product = context.Products.Include(p => p.Category).Single(p => p.ProductId == SelectedProduct.Id); } product.Name = SelectedProduct.Name; product.MinStock = SelectedProduct.MinStock; product.Category = context.Categories.Find(SelectedProduct.CategoryId); product.SellPrice = SelectedProduct.SellPrice; product.Mesurement = context.Measurements.Find(SelectedProduct.MeasurementId); context.Entry(product).State = SelectedProduct.Id == 0 ? EntityState.Added : EntityState.Modified; context.SaveChanges(); LoadProduct(); SelectedProduct = new ProductAux(); } }
private void OnUpdateSale() { using (MFSContext context = new MFSContext()) { Sale order = new Sale() { SaleId = 0 }; int isNewSale = 0; if (SelectedSale.SaleID != 0) { isNewSale = 1; order = context.Sales.Include(o => o.User).Include(o => o.Customer).Single(o => o.SaleId == SelectedSale.SaleID); } order.Date = SelectedSale.Date; order.Customer = context.Customers.Find(SelectedSale.CustomerId); order.User = context.Users.Find(UserLogin.Id); order.CodSale = SelectedSale.CodSale; context.Entry(order).State = SelectedSale.SaleID == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); LoadSale(); //Nueva venta if (isNewSale == 0) { SaleDetailView orderDetailView = new SaleDetailView(); orderDetailView.SaleId.Text = Convert.ToString(order.SaleId); orderDetailView.ShowDialog(); } } }
public void OnUpdateSuplier() { using (MFSContext context = new MFSContext()) { context.Entry(selectedSuplier).State = (selectedSuplier.SuplierId == 0) ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); } LoadSupliers(); }
public void OnUpdateCustomer() { if (!CustomerValidation()) { return; } using (MFSContext context = new MFSContext()) { SelectedCustomer.User = context.Users.Find(UserLogin.Id); context.Entry(selectedCustomer).State = (selectedCustomer.CustomerId == 0) ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); } LoadCustomers(); }
public void OnUpdateCategory() { if (!CategoryValidation()) { return; } using (MFSContext context = new MFSContext()) { SelectedCategory.User = context.Users.Find(UserLogin.Id); context.Entry(selectedCategory).State = (selectedCategory.CategoryId == 0) ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); } LoadCategories(); SelectedCategory = new Category(); }
public void OnUpdateUser() { if (!UserValidation()) { return; } using (MFSContext context = new MFSContext()) { SelectedUser.Role = context.Roles.Where(r => r.Name == ComboBoxRole.Content.ToString()).FirstOrDefault(); context.Entry(selectedUser).State = (selectedUser.UserId == 0) ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); } LoadUsers(); SelectedUser = new User(); }
public void OnUpdateMeasurement() { if (!MeasurementValidation()) { return; } using (MFSContext context = new MFSContext()) { SelectedMeasurement.User = context.Users.Find(UserLogin.Id); context.Entry(selectedMeasurement).State = (selectedMeasurement.MeasurementId == 0) ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; context.SaveChanges(); } LoadMeasurements(); SelectedMeasurement = new Measurement(); }
private void OnDeleteOrder() { Order orderSelected; using (MFSContext context = new MFSContext()) { orderSelected = context.Orders.Find(SelectedOrder.OrderID); orderSelected.Remove = 1; ICollection <OrderDetail> orderDetail = orderSelected.OrderDetail; if (orderDetail != null) { foreach (var od in orderDetail) { od.Remove = 1; } } context.Entry(orderSelected).State = EntityState.Modified; MessageBox.Show("Order eliminada correctamente"); } }