public async Task<IHttpActionResult> Post(Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } context.Categories.Add(category); await context.SaveChangesAsync(); return Created(category); }
private void AddCategory(IConfirmation confirmation) { System.Windows.Controls.TextBox tb = confirmation.Content as System.Windows.Controls.TextBox; if(confirmation.Confirmed && !string.IsNullOrEmpty(tb.Text)) { Category newCategory = new Category(); newCategory.Name = tb.Text; _client.Context.AddToCategories(newCategory); _client.Context.SaveChanges(); Categories.Add(newCategory); } }