Exemplo n.º 1
0
        public IActionResult PutCustomer(string key, [FromBody] Models.Northwind.Customer newItem)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

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

                this.OnCustomerUpdated(newItem);
                this.context.Customers.Update(newItem);
                this.context.SaveChanges();

                return(new NoContentResult());
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 2
0
        public IActionResult Post([FromBody] Models.Northwind.Customer item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

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

                this.OnCustomerCreated(item);
                this.context.Customers.Add(item);
                this.context.SaveChanges();

                return(Created($"odata/Northwind/Customers/{item.CustomerID}", item));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 3
0
 partial void OnCustomerUpdated(Models.Northwind.Customer item);
Exemplo n.º 4
0
 partial void OnCustomerDeleted(Models.Northwind.Customer item);