コード例 #1
0
        public IActionResult Post([FromBody] Models.Northwind.CustomerCustomerDemo item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

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

                this.OnCustomerCustomerDemoCreated(item);
                this.context.CustomerCustomerDemos.Add(item);
                this.context.SaveChanges();

                var keyCustomerID     = item.CustomerID;
                var keyCustomerTypeID = item.CustomerTypeID;
                var itemToReturn      = this.context.CustomerCustomerDemos
                                        .Where(i => i.CustomerID == keyCustomerID && i.CustomerTypeID == keyCustomerTypeID)
                                        .Include(i => i.Customer)
                                        .Include(i => i.CustomerDemographic)
                                        .FirstOrDefault();

                return(new JsonResult(itemToReturn, new Newtonsoft.Json.JsonSerializerSettings
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
                    DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc
                })
                {
                    StatusCode = 201
                });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
コード例 #2
0
        public IActionResult Post([FromBody] Models.Northwind.CustomerCustomerDemo item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

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

                this.OnCustomerCustomerDemoCreated(item);
                this.context.CustomerCustomerDemos.Add(item);
                this.context.SaveChanges();

                var keyCustomerID     = item.CustomerID;
                var keyCustomerTypeID = item.CustomerTypeID;

                var itemToReturn = this.context.CustomerCustomerDemos.Where(i => i.CustomerID == keyCustomerID && i.CustomerTypeID == keyCustomerTypeID);

                Request.QueryString = Request.QueryString.Add("$expand", "Customer,CustomerDemographic");

                return(new ObjectResult(SingleResult.Create(itemToReturn))
                {
                    StatusCode = 201
                });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
コード例 #3
0
 partial void OnCustomerCustomerDemoUpdated(Models.Northwind.CustomerCustomerDemo item);