public IActionResult Post([FromBody] Models.Northwind.Employee item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

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

                this.OnEmployeeCreated(item);
                this.context.Employees.Add(item);
                this.context.SaveChanges();

                var key = item.EmployeeID;

                var itemToReturn = this.context.Employees.Where(i => i.EmployeeID == key);

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

                return(new ObjectResult(SingleResult.Create(itemToReturn))
                {
                    StatusCode = 201
                });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Post([FromBody] Models.Northwind.Employee item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

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

                this.OnEmployeeCreated(item);
                this.context.Employees.Add(item);
                this.context.SaveChanges();

                var key          = item.EmployeeID;
                var itemToReturn = this.context.Employees
                                   .Where(i => i.EmployeeID == key)
                                   .Include(i => i.Employee1)
                                   .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));
            }
        }
Ejemplo n.º 3
0
 partial void OnEmployeeUpdated(Models.Northwind.Employee item);
Ejemplo n.º 4
0
 partial void OnEmployeeDeleted(Models.Northwind.Employee item);