public ActionResult <List <Menu> > GetKaiba() // returns a list of the menus { // create DbAccessManagement object DbAccessManagement DAM = new DbAccessManagement(); // return the list of menus return(DAM.getMenus()); // This is all test code /* * Menu testMenu = new Menu(1, "NEW_MENU", "DESCRIPTIONDFSJGH", 30000); * DAM.InsertMenu(testMenu); * DAM.DeleteMenu(3); * * Section testSection = new Section(1, "SECTION_TEST", "MY_LOVELY_SECTION_DESCRIPT", 30000, "NO_PICS", 1); * DAM.InsertSection(testSection); * DAM.DeleteSection(5); * * Item testItem = new Item(1, "ITEM_NAME", "ITEM_DESC", 20000, "LOVELY_PICTURE_OF_SOUP", 1); * DAM.InsertItem(testItem); * DAM.DeleteSection(9); * * Priceline testPrice = new Priceline(1, "68 Orders", (decimal) 100.99, 10000, 1); * DAM.InsertPriceline(testPrice); * DAM.DeletePriceline(11); * * * return DAM.GetSectionsInMenu(1); */ }
public ActionResult <List <Menu> > GetMenus() // returns a list of the menus { // create DbAccessManagement object DbAccessManagement DAM = new DbAccessManagement(); // return the list of menus System.Diagnostics.Debug.WriteLine("MenuCont: GetMenus() "); return(DAM.getMenus()); }
[HttpPut] // route = PUT /api/item // Note that it uses PUT instead of GET or POST public IActionResult UpdateItem(Item item) { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.UpdateItem(item); if (result) { return(NoContent()); } else { return(NotFound()); } }
[HttpPut] // route = PUT /api/section // Note that it uses PUT instead of GET or POST public IActionResult UpdateSection(Section section) { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.UpdateSection(section); if (result) { return(NoContent()); } else { return(NotFound()); } }
[HttpPut] // route = PUT /api/priceline // Note that it uses PUT instead of GET or POST public IActionResult UpdatePriceline(Priceline priceline) { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.UpdatePriceline(priceline); if (result) { return(NoContent()); } else { return(NotFound()); } }
[HttpPost] // Route = /api/item public IActionResult CreateItem(Item item) // POST request that takes JSON from the request body and builds a Item object // returns Content Created (201) if successful, returns server error (500) if unsuccessful { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.InsertItem(item); if (result) { return(StatusCode(201)); } else { return(StatusCode(500)); } }
[HttpPost("/menu")] // Route = /api/kaiba/menu public IActionResult CreateKaiba(Menu menu) // POST request that takes JSON from the request body and builds a Menu object // returns NoContent (204) if successful, returns server error (500) { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.InsertMenu(menu); if (result) { return(StatusCode(201)); } else { return(StatusCode(500)); } }
[HttpPut] // route = PUT /api/menu // Note that it uses PUT instead of GET or POST public IActionResult UpdateMenu(Menu menu) // takes a menu object from the JSON body and updates that record // returns NoContent (204) if successful, NotFound (404) if not { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.UpdateMenu(menu); if (result) { return(NoContent()); } else { return(NotFound()); } }
[HttpDelete] // Route = DELETE /api/item // but uses the DELETE method (as opposed to the usual GET or POST public IActionResult DeleteItem(Item item) // takes a Item object from the JSON body and deletes that record // it only requires the id field, and ignores everything else // returns NotFound (404) if unsuccessful, returns NoContent (204) if successful { DbAccessManagement DAM = new DbAccessManagement(); bool result = DAM.DeleteItem(item.Id); if (result) { return(NoContent()); } else { return(NotFound()); } }
[HttpGet("{id}", Name = "GetItem")] // Route = /api/item/2 public ActionResult <Item> GetItem(int id) // takes a Item id as a url parameter and returns a Item object with the corresponding information // the Item will contain pricelines { DbAccessManagement DAM = new DbAccessManagement(); // get the Item Item item = DAM.GetItem(id); // if it's null, then the Item wasn't found if (item == null) { // return a 404 ERROR return(NotFound()); } else //otherwise return the Item { return(item); } }
[HttpGet("{id}")] // Route = /api/kaiba/2 public ActionResult <Menu> GetKaiba(int id) // takes a menu id as a url parameter and returns a menu object with the corresponding information // the menu will contain sections, which contain items, which contain pricelines { DbAccessManagement DAM = new DbAccessManagement(); // get the sections in that menu Menu menu = DAM.getMenu(id); // if the list is null, then the menu wasn't found if (menu == null) { // return a 404 ERROR return(NotFound()); } else //otherwise return the menu { return(menu); } }
[HttpGet("{id}", Name = "GetSection")] // Route = /api/section/2 public ActionResult <Section> GetSection(int id) // takes a section id as a url parameter and returns a section object with the corresponding information // the section will contain items, which contain pricelines { DbAccessManagement DAM = new DbAccessManagement(); // get the section Section section = DAM.GetSection(id); // if it's null, then the section wasn't found if (section == null) { // return a 404 ERROR return(NotFound()); } else //otherwise return the section { return(section); } }
[HttpGet("{id}", Name = "GetPriceline")] // Route = /api/priceline/2 public ActionResult <Priceline> GetPriceline(int id) // takes a Priceline id as a url parameter and returns a Priceline object with the corresponding information // the Priceline will contain pricelines { DbAccessManagement DAM = new DbAccessManagement(); // get the Priceline Priceline priceline = DAM.GetPriceline(id); // if it's null, then the Priceline wasn't found if (priceline == null) { // return a 404 ERROR return(NotFound()); } else //otherwise return the Priceline { return(priceline); } }
public ActionResult <List <Menu> > Get() { DbAccessManagement DAM = new DbAccessManagement(); return(DAM.getMenus()); //return new string[] { DbAccessManagement.DBTest2() }; /* * if(DbAccessManagement.DBTest()) * { * return new string[] {"connected"}; * } * else * { * return new string[] { "failed" }; * } */ //return new string[] { "value1", "value2" }; }