public async Task <ActionResult> SaveCategory(Category category) { if (category.Id == 0) { var response = await _categoryApiClient.AddCategory(category); string result = await response.Content.ReadAsStringAsync(); switch ((int)response.StatusCode) { case (int)HttpStatusCode.OK: var data = JsonConvert.DeserializeObject <Category>(result); return(Json(new { Success = true, data = data }, JsonRequestBehavior.AllowGet)); case (int)HttpStatusCode.NotFound: return(HttpNotFound()); default: return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } else { //update var existCategory = categories.Find(f => f.Id == category.Id); existCategory.Name = category.Name; existCategory.Description = category.Description; } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
private void btnAdd_Click(object sender, EventArgs e) { _categoryApiClient.AddCategory(new Northind.Entities.Concrete.Category() { Name = textBoxDescription.Text, Description = textBoxDescription.Text }); CetegoriesRead(); }