private void Button_ClickBasket(object sender, RoutedEventArgs e) { var CNum = db.Clients.Where(n => n.Email == email).FirstOrDefault(); var PNUm = Convert.ToInt32((sender as Button).Uid); var checkBas = db.Basketts.Where(b => b.ProdNum == PNUm && b.ClientNum == CNum.ClientNum).FirstOrDefault(); var checkProdQuan = db.Products.Where(p => p.ProductNum == PNUm).FirstOrDefault(); if (checkBas == null && checkProdQuan.Quantity > 0) { Basketts newPoint = new Basketts { ClientNum = CNum.ClientNum, ProdNum = PNUm, Quantity = 1 }; db.Basketts.Add(newPoint); MessageBox.Show("Товар добавлен в корзину"); } else if (checkProdQuan.Quantity > checkBas.Quantity + 1) { checkBas.Quantity += 1; MessageBox.Show("Увеличели количество товара в корзине"); } else { MessageBox.Show("Товара закончился"); } db.SaveChanges(); }
private void Button_ClickBasket(object sender, RoutedEventArgs e) { CompEntities5 db = new CompEntities5(); var CNum = db.Clients.Where(n => n.Email == email).FirstOrDefault(); var PNUm = Convert.ToInt32((sender as Button).Uid); var checkBas = db.Basketts.Where(b => b.ProdNum == PNUm && b.ClientNum == CNum.ClientNum).FirstOrDefault(); if (checkBas == null) { Basketts newPoint = new Basketts { ClientNum = CNum.ClientNum, ProdNum = PNUm, Quantity = 1 }; db.Basketts.Add(newPoint); } else { checkBas.Quantity += 1; } db.SaveChanges(); MessageBox.Show("Товар добавлен в корзину"); }