コード例 #1
0
        public IActionResult PutShipper(int key, [FromBody] Models.Northwind.Shipper newItem)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (newItem == null || (newItem.ShipperID != key))
                {
                    return(BadRequest());
                }

                this.OnShipperUpdated(newItem);
                this.context.Shippers.Update(newItem);
                this.context.SaveChanges();

                return(new NoContentResult());
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
コード例 #2
0
        public IActionResult Post([FromBody] Models.Northwind.Shipper item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (item == null)
                {
                    return(BadRequest());
                }

                this.OnShipperCreated(item);
                this.context.Shippers.Add(item);
                this.context.SaveChanges();

                return(Created($"odata/Northwind/Shippers/{item.ShipperID}", item));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
コード例 #3
0
        public IActionResult PutShipper(int key, [FromBody] Models.Northwind.Shipper newItem)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (newItem == null || (newItem.ShipperID != key))
                {
                    return(BadRequest());
                }

                this.OnShipperUpdated(newItem);
                this.context.Shippers.Update(newItem);
                this.context.SaveChanges();

                var itemToReturn = this.context.Shippers.Where(i => i.ShipperID == key);
                return(new ObjectResult(SingleResult.Create(itemToReturn)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
コード例 #4
0
 partial void OnShipperUpdated(Models.Northwind.Shipper item);
コード例 #5
0
 partial void OnShipperDeleted(Models.Northwind.Shipper item);