public IActionResult PutCategory(int key, [FromBody] Models.Northwind.Category newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.CategoryID != key)) { return(BadRequest()); } this.OnCategoryUpdated(newItem); this.context.Categories.Update(newItem); this.context.SaveChanges(); return(new NoContentResult()); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.Northwind.Category item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnCategoryCreated(item); this.context.Categories.Add(item); this.context.SaveChanges(); return(Created($"odata/Northwind/Categories/{item.CategoryID}", item)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult PutCategory(int?key, [FromBody] Models.Northwind.Category newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.CategoryID != key)) { return(BadRequest()); } this.OnCategoryUpdated(newItem); this.context.Categories.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.Categories.Where(i => i.CategoryID == key); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnCategoryUpdated(Models.Northwind.Category item);