public IActionResult Post([FromBody] Models.ConData.Country item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnCountryCreated(item); this.context.Countries.Add(item); this.context.SaveChanges(); return(Created($"odata/ConData/Countries/{item.CountryID}", item)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult PutCountry(int key, [FromBody] Models.ConData.Country newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.CountryID != key)) { return(BadRequest()); } this.OnCountryUpdated(newItem); this.context.Countries.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.Countries.Where(i => i.CountryID == key); this.OnAfterCountryUpdated(newItem); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnAfterCountryUpdated(Models.ConData.Country item);
partial void OnAfterCountryDeleted(Models.ConData.Country item);
partial void OnCountryCreated(Models.ConData.Country item);