[OrderController.cs]
namespace AngularwithASPCore.Controllers
{
[Produces("application/json")]
[Route("api/Orders")]
public class OrdersController : Controller
{
...
// POST: api/Orders
[HttpPost]
public object Post([FromBody]OrdersDetails value)
{
OrdersDetails.GetAllRecords().Insert(0, value);
var data = OrdersDetails.GetAllRecords().ToList();
return Json(new { result = data, count = data.Count });
}
// PUT: api/Orders/5
[HttpPut]
public object Put(int id, [FromBody]OrdersDetails value) //update operation
{
var ord = value;
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.EmployeeID = ord.EmployeeID;
val.CustomerID = ord.CustomerID;
val.Freight = ord.Freight;
val.OrderDate = ord.OrderDate;
val.ShipCity = ord.ShipCity;
return value;
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id:int}")]
[Route("Orders/{id:int}")]
public object Delete(int id)
{
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault());
return Json(id);
}
}
} |