public ActionResult <Burger> GetOne(string burgerId) { try { Burger foundBurger = FakeDB.Burgers.Find(burger => burger.Id == burgerId); if (foundBurger == null) { throw new Exception("Invalid Id"); } return(Ok(foundBurger)); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult <string> Delete(string id) { try { Burger burgerToDelete = FakeDB.Burgers.Find(b => b.Id == id); if (burgerToDelete == null) { throw new Exception("Invalid Id"); } FakeDB.Burgers.Remove(burgerToDelete); return(Ok("Delorted")); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult <Burger> Edit(string id, [FromBody] Burger updatedBurger) { try { Burger burgerToUpdate = FakeDB.Burgers.Find(b => b.Id == id); if (burgerToUpdate == null) { throw new Exception("Invalid Id"); } //NOTE if this was not required burgerToUpdate.Title = updatedBurger.Title == null ? burgerToUpdate.Title : updatedBurger.Title; burgerToUpdate.Description = updatedBurger.Description; burgerToUpdate.Price = updatedBurger.Price; return(Ok(burgerToUpdate)); } catch (System.Exception err) { return(BadRequest(err.Message)); } }