private void button2_Click(object sender, EventArgs e) { if (CartService.Cart.CartDetails == null || !CartService.Cart.CartDetails.Any()) { MessageBox.Show("Nu aveti nimic in cos."); return; } foreach (var cartItem in CartService.Cart.CartDetails) { if (cartItem.PartId.HasValue) { // this is a part var part = mm.db.Parts.Find(cartItem.PartId.Value); if (part != null) { part.Quantity -= cartItem.Quantity; part.SoldQuantity += cartItem.Quantity; LoggingService.Log(Enums.ActionsEnum.Vanzare_Piesa, part.Price * cartItem.Quantity, "S-a vandut piesa- " + part.Name + " nr bucati vandute- " + cartItem.Quantity + " pret/buc" + part.Price); part.isAvailable = false; if (part.Quantity == 0) { part.InStock = false; } } } else { // this is a service // TODO } } DialogResult result = MessageBox.Show("Adaugare date cumparator? ", "Confirmare", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { // client is null here new ClientAddForm(this).ShowDialog(); // open the dialog and pass the null client to it to be populated // here we have the populated AND SAVED client via PopulateClient method if (client == null || client.Id <= 0) { client = new ClientOfPark() { Name = "_______________", RegNo = "_______________", J = "_______________", Address = "_______________", BankAccount = "_______________", BankName = "_______________", Phone = "_______________" }; } } else if (result == DialogResult.No) { client = new ClientOfPark() { Name = "_______________", RegNo = "_______________", J = "_______________", Address = "_______________", BankAccount = "_______________", BankName = "_______________", Phone = "_______________" }; } var dbCart = mm.db.Carts.Find(CartService.Cart.Id); dbCart.IsSold = true; client.IsActive = false; mm.db.SaveChanges(); // Trigger PDF gen PdfService.GeneratePdf(CartService.Cart, client); CartService.Cart = new Cart(); dataListView1.DataSource = new List <object>(); this.Close(); MessageBox.Show("Vandute."); mm.ReCheck(); }