Skip to content

Instantly share code, notes, and snippets.

@cbdribamar
Created February 11, 2026 15:33
Show Gist options
  • Select an option

  • Save cbdribamar/7b2ec243f354a49595dbfc103a9295ad to your computer and use it in GitHub Desktop.

Select an option

Save cbdribamar/7b2ec243f354a49595dbfc103a9295ad to your computer and use it in GitHub Desktop.
Interview | Q3
public class OrdersApiController : UmbracoApiController
{
private readonly IUmbracoDatabase _database;
public OrdersApiController(IUmbracoDatabase database)
{
_database = database;
}
[HttpPost]
public IActionResult CreateOrder(string customerName, string productName, int quantity)
{
var sql = "INSERT INTO Orders (CustomerName, ProductName, Quantity, OrderDate) " +
"VALUES ('" + customerName + "', '" + productName + "', " + quantity + ", GETDATE())";
_database.Execute(sql);
var orderId = _database.ExecuteScalar<int>(
"SELECT TOP 1 Id FROM Orders WHERE CustomerName = '" + customerName + "' ORDER BY Id DESC"
);
return Ok(new { OrderId = orderId, Message = "Order created successfully" });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment