public bool KoopProduct(string gebruikersnaam, int productid, int tal, double prijs) { using (WinkelModel db = new WinkelModel()) { tbProduct product = db.tbProductSet.Single(p => p.Id == productid); tbGebruiker gebruiker = db.tbGebruikerSet.Single(g => g.gebruikersnaam == gebruikersnaam); if (gebruiker == null) { return(false); } else { for (int i = 0; i < tal; i++) { product.aantal = product.aantal - tal; tbAankoopRegel ar = new tbAankoopRegel { Product_Id = productid, aantal = tal }; tbAankoop ak = new tbAankoop { Gebruiker_Id = gebruiker.Id, aankoopdatum = DateTime.Today }; gebruiker.saldo -= prijs * tal; ak.AankoopRegels.Add(ar); db.tbAankoopSet.Add(ak); } db.SaveChanges(); return(true); } } }
public bool Registreer(string gebruikersnaam, string wachtwoord) { try { using (WinkelModel db = new WinkelModel()) { if (BestaatGebruiker(gebruikersnaam)) { return(false); } tbGebruiker gr = new tbGebruiker { gebruikersnaam = gebruikersnaam, wachtwoord = wachtwoord, saldo = 1000 }; db.tbGebruikerSet.Add(gr); db.SaveChanges(); return(true); } } catch (Exception e) { return(false); } }