public ActionResult Succes(Klant klant) { System.Diagnostics.Debug.WriteLine("In Succes"); try { WinkelWagen ww = GetWinkelWagenFromSession(); if (ww == null) return RedirectToAction("Index", "Home"); if (ww.Producten.Count == 0) return RedirectToAction("Index", "Home"); if (!ModelState.IsValid) { System.Diagnostics.Debug.WriteLine("Modelstate is not valid"); return View(false); } System.Threading.Thread thread = new System.Threading.Thread(() => AddWithSoap(ww, klant)); thread.Start(); Session["cart"] = new WinkelWagen(); return View(true); } catch (Exception) { return View(false); } }
private void AddWithSoap(WinkelWagen winkelWagen, Klant klant) { SOAPService.SOAPService SoapService = new SOAPService.SOAPService(); db.Klanten.Add(klant); Order order = new Order { klant = klant }; var checklist = new List<int>(); foreach (var item in winkelWagen.Producten) { if (!checklist.Contains(item.id)) { var aantal = 0; foreach (var product in winkelWagen.Producten) { if (product.id == item.id) aantal++; } System.Diagnostics.Debug.WriteLine("aantal: " + aantal); db.Orderregels.Add( new Orderregel { aantal = aantal, product = db.Producten.Find(item.id), order = order } ); checklist.Add(item.id); } } // GetAcceptGiro heeft de 30 seconden timer/vertraging order.uniekGetal = SoapService.GetAcceptGiro(klant.voornaam + " " + klant.achternaam, klant.adres, winkelWagen.Totaal()); db.Orders.Add(order); db.SaveChanges(); }
// GET: /WinkelWagen public WinkelWagen Index() { var winkelWagen = new WinkelWagen(); winkelWagen.Producten = GetProductenInWinkelwagen(); return winkelWagen; }