コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
 partial void OnAfterCountryUpdated(Models.ConData.Country item);
コード例 #4
0
 partial void OnAfterCountryDeleted(Models.ConData.Country item);
コード例 #5
0
 partial void OnCountryCreated(Models.ConData.Country item);