public async Task <IActionResult> Post([FromBody] Category category) { #if !NETCORE10 if (!TryValidateModel(category)) { return(BadRequest(ModelState)); } #endif _db.Categories.Add(category); await _db.SaveChangesAsync(); #if NETCORE10 var req = HttpContext.Request; var locationUri = $"{req.Protocol}://{req.Host}/{req.Path}(CategoryID={category.CategoryID})"; return(Created(locationUri, category)); #else return(Created(category)); #endif }
public async Task <IActionResult> Post([FromBody] Order order) { #if !NETCORE10 if (!TryValidateModel(order)) { return(BadRequest(ModelState)); } #endif _db.Orders.Add(order); await _db.SaveChangesAsync(); #if NETCORE10 var req = HttpContext.Request; var locationUri = $"{req.Protocol}://{req.Host}/{req.Path}(OrderID={order.OrderID})"; return(Created(locationUri, order)); #else return(Created(order)); #endif }