Created
February 11, 2026 15:33
-
-
Save cbdribamar/7b2ec243f354a49595dbfc103a9295ad to your computer and use it in GitHub Desktop.
Interview | Q3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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