public async Task <IActionResult> Archiveren(int?Id) { Bestelling res = await _context.Bestellingen.Where(x => x.Id == Id).FirstOrDefaultAsync(); Consumptie y = await _context.Consumpties.Where(x => x.Id == res.ConsumptieId).FirstOrDefaultAsync(); BestellingArchief archief = new BestellingArchief { TafelsId = res.TafelsId, Aantal = res.Aantal, Bestellingsdatum_afgerond = res.Bestellingsdatum_afgerond, Bestellingsdatum_Tijd = res.Bestellingsdatum_Tijd, Consumptie = y.Naam, Archiveerdatum = DateTime.Now }; //BestellingArchief bes = new BestellingArchief(); //bes.TafelsId = res.TafelsId; //bes.Bestellingsdatum_afgerond = res.Bestellingsdatum_afgerond; //bes.Bestellingsdatum_Tijd = res.Bestellingsdatum_Tijd; //bes.Consumptie = y.Naam; //bes.Archiveerdatum = DateTime.Now; await _context.BestellingArchief.AddAsync(archief); await _context.SaveChangesAsync(); _context.Bestellingen.Remove(res); await _context.SaveChangesAsync(); return(RedirectToAction("AfgerondeBestellingen")); }
public async Task <IActionResult> DeleteArchief_Single(int?Id) { BestellingArchief arch = await _context.BestellingArchief.Where(x => x.Id == Id).SingleOrDefaultAsync(); _context.BestellingArchief.Remove(arch); await _context.SaveChangesAsync(); return(RedirectToAction("Archief")); }
public async Task <IActionResult> Afrekenen(int id) { //Infotmatie ophalen double TotaalPrijs = 0; Tafels tafel = await _context.Tafels.Where(x => x.Id == id).FirstOrDefaultAsync(); List <Bestelling> bestellingen = await _context.Bestellingen.Where(x => x.TafelsId == id && x.Afgerond == true).ToListAsync(); //Bestellingen naar het archief plaatsen en totaalprijs berekenen foreach (var item in bestellingen) { TotaalPrijs += _context.Consumpties.Where(x => x.Id == item.ConsumptieId).FirstOrDefault().Prijs; BestellingArchief archief = new BestellingArchief { TafelsId = item.TafelsId, Consumptie = item.Consumptie.Naam, Archiveerdatum = DateTime.Now, Bestellingsdatum_afgerond = item.Bestellingsdatum_afgerond, Bestellingsdatum_Tijd = item.Bestellingsdatum_Tijd, }; await _context.BestellingArchief.AddAsync(archief); Console.WriteLine(item.Consumptie.Naam); } //Database updaten _context.RemoveRange(bestellingen); tafel.Bezet = false; _context.Tafels.Update(tafel); await _context.SaveChangesAsync(); ViewBag.totaal = TotaalPrijs; ViewBag.TafelId = tafel.Id; Console.WriteLine("TAFEL ID : " + tafel.Id); return(new ViewAsPdf(bestellingen)); }