Add POST methods
This commit is contained in:
parent
d3c1749360
commit
4857c06630
@ -13,7 +13,8 @@ public class CategoryController : ControllerBase
|
||||
_helper = helper;
|
||||
}
|
||||
[HttpGet]
|
||||
public IEnumerable<Category> GetCategories() {
|
||||
public IEnumerable<Category> GetCategories()
|
||||
{
|
||||
var command = _helper.Connection.CreateCommand();
|
||||
command.CommandText =
|
||||
@"
|
||||
@ -31,4 +32,21 @@ public class CategoryController : ControllerBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult PostCategory([FromBody] Category category)
|
||||
{
|
||||
var command = _helper.Connection.CreateCommand();
|
||||
command.CommandText =
|
||||
$"INSERT INTO categories (category_id, category_name) VALUES ({category.Id}, '{category.Name}')";
|
||||
try
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,21 @@ public class ItemController : ControllerBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult PostItem([FromQuery] int? productId, [FromQuery] int? categoryId)
|
||||
{
|
||||
var command = _helper.Connection.CreateCommand();
|
||||
command.CommandText =
|
||||
$"INSERT INTO grocery_store (product_id, category_id) VALUES ({productId}, {categoryId})";
|
||||
try
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,21 @@ public class ProductController : ControllerBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult PostProduct([FromBody] Product product)
|
||||
{
|
||||
var command = _helper.Connection.CreateCommand();
|
||||
command.CommandText =
|
||||
$"INSERT INTO products (product_id, product_name) VALUES ({product.Id}, '{product.Name}')";
|
||||
try
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user