[controller]
private NORTHWNDEntities db = new NORTHWNDEntities();
public ActionResult GetData(Syncfusion.JavaScript.DataManager value) //To render all Kanban cards. {
var DataSource = db.Tasks.ToList();
DataResult result1 = new DataResult();
DataOperations operation = new DataOperations();
result1.result = DataSource;
result1.count = DataSource.AsQueryable().Count();
if (value.Skip > 0)
result1.result = operation.PerformSkip(result1.result, value.Skip);
if (value.Take > 0)
result1.result = operation.PerformTake(result1.result, value.Take);
if (value.Select != null && value.Select.Count >0)
return Json(result1.result, JsonRequestBehavior.AllowGet);
return Json(result1, JsonRequestBehavior.AllowGet);
}
//Edit multiple cards for priority drag and drop
public ActionResult Crud(List<Task> changed, List<Task> added, List<Task> deleted)
{
//Performing insert operation
if (added != null && added.Count() > 0)
{
foreach (var temp in added)
{
db.Tasks.Add(temp);
}
}
////Performing update operation
if (changed != null && changed.Count() > 0)
{
foreach (var temp in changed)
{
Task old = db.Tasks.Where(o => o.Id == temp.Id).SingleOrDefault();
if (old != null)
{
db.Entry(old).CurrentValues.SetValues(temp);
}
}
}
//Performing delete operation
if (deleted != null && deleted.Count() > 0)
{
foreach (var temp in deleted)
{
db.Tasks.Remove(db.Tasks.Where(o => o.Id == temp.Id).SingleOrDefault());
}
}
db.SaveChanges();
var data = db.Tasks.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
} |