public IHttpActionResult Post(MenuPostDto menu) { using (var helper = new DataBaseHelper()) { var id = helper.CreateOrUpdateMenuItem(new MenuItem { Swedish = menu.Swedish, English = menu.English, Navigation = menu.Navigation }); if (id == Guid.Empty) { return(BadRequest()); } return(Ok(id)); } }
public async Task <IActionResult> Post([FromBody] MenuPostDto menu) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Menu newMenu = new Menu() { Name = menu.Name }; await _context.Menus.AddAsync(newMenu); await _context.SaveChangesAsync(); return(Ok(menu)); }
public async Task <bool> CreateMenu(int id, MenuPostDto menu) { EnsureClient(); bool success = false; try { var response = await _client.PostAsJsonAsync("api/menu" + id, menu); response.EnsureSuccessStatusCode(); success = true; } catch (HttpRequestException ex) { _logger.LogError("Caught an error when creating a new menu at id " + id + ". Exception: " + ex); } return(success); }
public async Task <MenuGetDto> UpdateMenu(int id, MenuPostDto menu) { EnsureClient(); MenuGetDto newMenu = null; try { var response = await _client.PutAsJsonAsync("api/menu/" + id, menu); response.EnsureSuccessStatusCode(); newMenu = await response.Content.ReadAsAsync <MenuGetDto>(); } catch (HttpRequestException ex) { _logger.LogError("Caught an error when deleting a menu at id " + id + ". Exception: " + ex); } return(newMenu); }