示例#1
0
 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));
     }
 }
示例#2
0
 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));
     }
 }
示例#3
0
 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));
     }
 }