public async Task <IActionResult> Producten(string documentId) { db = FirestoreDatabase.LoadDatabase(); CollectionReference klantenColl = db.Collection("Klanten"); DocumentReference document = klantenColl.Document(documentId); DocumentSnapshot klantMetNaam = await document.GetSnapshotAsync(); DocumentKlant documentKlant = new DocumentKlant { DocumentId = document.Id, Klant = klantMetNaam.ConvertTo <Klant>() }; Query query = klantenColl.WhereEqualTo("Naam", documentKlant.Klant.Naam); FirestoreChangeListener listener = query.Listen(snapshot => { foreach (DocumentChange change in snapshot.Changes) { DocumentSnapshot documentSnapshot = change.Document; if (documentSnapshot.Exists) { documentKlant.DocumentId = document.Id; documentKlant.Klant = documentSnapshot.ConvertTo <Klant>(); } } }); await listener.StopAsync(); return(View(documentKlant)); }
// Opdracht a: Maak een webpagina met een overzicht van alle klanten public async Task <IActionResult> Index() { db = FirestoreDatabase.LoadDatabase(); // Fetch collection genaamd klanten CollectionReference coll = db.Collection("Klanten"); List <DocumentKlant> documentKlantLijst = new List <DocumentKlant>(); // Maak snapshot van hele klanten collection QuerySnapshot alleKlanten = await coll.GetSnapshotAsync(); foreach (DocumentSnapshot document in alleKlanten.Documents) { DocumentKlant documentKlant = new DocumentKlant { DocumentId = document.Id, Klant = document.ConvertTo <Klant>() }; documentKlantLijst.Add(documentKlant); } return(View(documentKlantLijst)); }