public IActionResult Get(int KlantId) { List <JoinedBestelling> bestToRet = new List <JoinedBestelling>(); var foundOrder = this._context.Bestellingen.Where(order => order.klantId == KlantId).ToArray(); JoinedBestelling[] res; foreach (Bestelling bestelling in foundOrder) { if ((bestelling.productId != 0) && (bestelling.klantId != 0)) { JoinedBestelling newBest = new JoinedBestelling { BestellingId = bestelling.BestellingId, productId = _context.Producten.Find(bestelling.productId), bestellingDatum = bestelling.bestellingDatum, verstuurDatum = bestelling.verstuurDatum, status = bestelling.status, groupId = bestelling.groupId, klantId = _context.Klanten.Find(bestelling.klantId) }; bestToRet.Add(newBest); } } if (foundOrder != null) { res = bestToRet.OrderByDescending((b) => b.groupId).ToArray(); return(Ok(res)); } else { return(NotFound(foundOrder)); } }
public IActionResult GetAll() { List <JoinedBestelling> bestToRet = new List <JoinedBestelling>(); JoinedBestelling[] res; foreach (Bestelling bestelling in _context.Bestellingen.AsEnumerable()) { if (bestelling.productId != 0) { JoinedBestelling newBest = new JoinedBestelling { BestellingId = bestelling.BestellingId, productId = _context.Producten.Find(bestelling.productId), bestellingDatum = bestelling.bestellingDatum, verstuurDatum = bestelling.verstuurDatum, status = bestelling.status, klantId = _context.Klanten.Find(bestelling.klantId), groupId = bestelling.groupId }; bestToRet.Add(newBest); } } if (bestToRet != null) { res = bestToRet.OrderByDescending((b) => b.groupId).ToArray(); return(Ok(res)); } else { return(NotFound(bestToRet)); } }