public IEnumerable <DessertDTO> GetDesserts(int id) { if (!_menusRepository.TryGetMenu(id, out var menu)) { return(new List <DessertDTO>()); //return NotFound(); } return(menu.MenuDesserts.Select(md => DessertDTO.MapDessert(md)).OrderBy(d => d.Naam)); }
public ActionResult <DessertDTO> GetDessert(int id, int dessertId) { if (!_menusRepository.TryGetMenu(id, out var menu)) { return(NotFound()); } MenuDessert menuDessert = menu.GetMenuDessert(dessertId); if (menuDessert == null) { return(NotFound()); } return(DessertDTO.MapDessert(menuDessert)); }
public ActionResult <DessertDTO> DeleteDessert(int id, int dessertId) { Menu menu = _menusRepository.GetBy(id); if (menu == null) { return(NotFound()); } Dessert dessert = menu.GetDessert(dessertId); if (dessert == null) { return(NotFound()); } var returnType = DessertDTO.MapDessert(menu.GetMenuDessert(dessertId)); menu.DeleteDessert(dessert); _menusRepository.SaveChanges(); return(returnType); }
public ActionResult <DessertDTO> PostDessert(int id, int dessertId) { if (!_menusRepository.TryGetMenu(id, out var menu)) { return(NotFound()); } _dessertsRepository.TryGetDessert(dessertId, out var dessert); //var dessertToCreate = new Dessert(dessert.Naam, dessert.Prijs, dessert.Hoeveelheid, dessert.Omschrijving, dessert.Foto); menu.AddDessert(dessert, DateTime.Now); _menusRepository.SaveChanges(); return(CreatedAtAction("GetDessert", new { id = menu.Id, dessertId = dessert.Id }, DessertDTO.MapDessert(menu.GetMenuDessert(dessert.Id)))); }