public void AddChatBericht(int id, ChatBericht chatbericht) { Passagier passagier = _passengerRepository.GetbyId(id); passagier.Groepschat.Chatberichten.Add(chatbericht); _passengerRepository.SaveChanges(); }
public List <ChatBericht> RetrieveAllChatBerichtenByOpdracht(int id) { try { using (_con) { _con.Open(); var cmdString = "SELECT * FROM ChatBericht WHERE hulpopdrachtId = @id"; var command = new SqlCommand(cmdString, _con); command.Parameters.AddWithValue("@id", id); var reader = command.ExecuteReader(); var ReturnList = new List <ChatBericht>(); while (reader.Read()) { var c = new ChatBericht(reader.GetDateTime(1), reader.GetString(2), reader.GetInt32(3), reader.GetInt32(4)); c.Id = reader.GetInt32(0); ReturnList.Add(c); } _con.Close(); reader.Close(); return(ReturnList); } } catch (Exception ex) { throw new DatabaseException("Er ging iets mis bij het ophalen van de gegevens", ex); } }
internal async void postChatBericht(string value) { Client = new HttpClient(); ChatBericht chatbericht = new ChatBericht(Zetel.Passagier.Voornaam, DateTime.Now, value); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(Api + "/Passagier/chatbericht/" + Zetel.Passagier.Id), Content = new StringContent(JsonConvert.SerializeObject(chatbericht), Encoding.UTF8, "application/json") }; ChatBerichten.Add(chatbericht); await Client.SendAsync(request); }
public async Task InitializeDataAsync() { _dbContext.Database.EnsureDeleted(); if (_dbContext.Database.EnsureCreated()) { Locatie o1 = new Locatie("Brussels", "Avenue 555", 50.900864, 4.484738); Locatie b1 = new Locatie("Iceland", "Brussel", 63.978513, -22.635057); Vlucht f1 = new Vlucht("UC751", o1, b1, 5, new Vliegtuig()); Passagier p1 = new Passagier(1, "Jan", "Janssens"); Passagier p2 = new Passagier(2, "Jef", "Vanvoort"); Passagier p3 = new Passagier(3, "Sara", "Verbeke"); Passagier p4 = new Passagier(4, "Celia", "Vermeulen"); p1.Meldingen.Add(new Melding() { Inhoud = "Welkom aan boord!" }); p2.Meldingen.Add(new Melding() { Inhoud = "Welkom aan boord!" }); p3.Meldingen.Add(new Melding() { Inhoud = "Welkom aan boord!" }); p4.Meldingen.Add(new Melding() { Inhoud = "Welkom aan boord!" }); _dbContext.Passagiers.AddRange(p1, p2, p3, p4); Zetel z1 = new Zetel(1, 'A', "Eerste klasse") { Passagier = p1 }; Zetel z2 = new Zetel(1, 'B', "Eerste klasse") { Passagier = p2 }; Zetel z3 = new Zetel(1, 'C', "Eerste klasse") { Passagier = p3 }; Zetel z4 = new Zetel(2, 'A', "Eerste klasse") { Passagier = p4 }; Zetel z5 = new Zetel(2, 'B', "Eerste klasse"); BestellingOptie optie1 = new BestellingOptie() { Naam = "Fristi", Type = BestellingType.Drinken, Prijs = 4.50 }; BestellingOptie optie2 = new BestellingOptie() { Naam = "Water", Type = BestellingType.Drinken, Prijs = 2 }; BestellingOptie optie3 = new BestellingOptie() { Naam = "Rijstpap", Type = BestellingType.Eten, Prijs = 7.50 }; BestellingOptie optie4 = new BestellingOptie() { Naam = "Steak Natuur", Type = BestellingType.Eten, Prijs = 25 }; _dbContext.BestellingOpties.AddRange(optie1, optie2, optie3, optie4); _dbContext.SaveChanges(); Bestelling bestelling1 = new Bestelling() { Afgehandeld = false, Passagier = p1 }; Bestelling bestelling2 = new Bestelling() { Afgehandeld = false, Passagier = p2 }; Bestelling bestelling3 = new Bestelling() { Afgehandeld = false, Passagier = p1 }; Bestelling bestelling4 = new Bestelling() { Afgehandeld = false, Passagier = p2 }; _dbContext.AddRange(bestelling1, bestelling2, bestelling3, bestelling4); _dbContext.SaveChanges(); BestellingTK tk1 = new BestellingTK { BestellingId = bestelling1.Id, BestellingOptie = optie1 }; BestellingTK tk2 = new BestellingTK { BestellingId = bestelling1.Id, BestellingOptie = optie3 }; BestellingTK tk3 = new BestellingTK { BestellingId = bestelling2.Id, BestellingOptie = optie2 }; BestellingTK tk4 = new BestellingTK { BestellingId = bestelling2.Id, BestellingOptie = optie4 }; BestellingTK tk5 = new BestellingTK { BestellingId = bestelling3.Id, BestellingOptie = optie1 }; BestellingTK tk6 = new BestellingTK { BestellingId = bestelling4.Id, BestellingOptie = optie2 }; _dbContext.BestellingTKs.AddRange(tk1, tk2, tk3, tk4, tk5, tk6); _dbContext.Zetels.AddRange(z1, z2, z3, z4, z5); _dbContext.Locaties.AddRange(o1, b1); _dbContext.Flights.Add(f1); Groepschat groepschat1 = new Groepschat("de coole chat"); groepschat1.Passagiers.Add(p1); groepschat1.Passagiers.Add(p2); ChatBericht cb1 = new ChatBericht(p1, DateTime.Now, "hallo"); ChatBericht cb2 = new ChatBericht(p2, DateTime.Now, "dag"); groepschat1.Chatberichten.Add(cb1); groepschat1.Chatberichten.Add(cb2); _dbContext.Add(groepschat1); await CreateUser("*****@*****.**", "*****@*****.**", "azerty123"); _dbContext.SaveChanges(); } }