Grid:
<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-data-manager id="myData" url="/api/Orders" adaptor="WebApiAdaptor" crossDomain="true"></e-data-manager>
...
</ejs-grid>
--------------------------------------------------------------------------------------
Controller Side:
namespace AngularwithASPCore.Controllers
{
[Produces("application/json")]
[Route("api/Orders")]
public class OrdersController : Controller
{
// GET: api/Orders
[HttpGet]
public object Get()
{
var queryString = Request.Query;
int skip = Convert.ToInt32(queryString["$skip"]);
int take = Convert.ToInt32(queryString["$top"]);
var data = OrdersDetails.GetAllRecords().ToList();
return take != 0 ? new { Items = data.Skip(skip).Take(take).ToList(), Count = data.Count() } : new { Items = data, Count = data.Count() };
}
// POST: api/Orders
[HttpPost]
public object Post([FromBody]OrdersDetails value)
{
OrdersDetails.GetAllRecords().Insert(0, value);
return value;
}
// PUT: api/Orders/5
[HttpPut]
public object Put(int id, [FromBody]OrdersDetails value)
{
var data = OrdersDetails.GetAllRecords().Where(or => or.OrderID == value.OrderID).FirstOrDefault();
if (data != null)
{
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 void Delete(int id)
{
var data = OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault();
OrdersDetails.GetAllRecords().Remove(data);
}
}
} |
public object Post([FromBody]OrdersDetails value)
{
//Here we have auto-incremented the identity column value So you can change based on your requirement
value.OrderID = OrdersDetails.GetAllRecords().First().OrderID + 10000;
OrdersDetails.GetAllRecords().Insert(0, value);
return value;
} |
public object Put([FromBody]OrdersDetails value)
{
var data = OrdersDetails.GetAllRecords().Where(or => or.OrderID == value.OrderID).FirstOrDefault();
if (data != null)
{
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;
} |