albert albert

albert albert

  • NA
  • 524
  • 0

Move up/down record with LINQ

Jul 4 2014 1:12 AM
Hi everybody,
 
I  have 2 buttons: UP and Down.
 
And if you press up , then the record has to goes up and for down - the record has to go down.
 
This is the ajax call: 
[code]
 
$.ajax({
type: 'POST',
url:Medicijnverstrekking.baseUrl + '/Medicijn/MoveUp/',
dataType: 'json',
data:{Id: dataItem.Id},
success: function (result) {
//$("#medicijnenGridVolgorde").data("kendoGrid").dataSource.data(result);
//if (newIndex != index) {
//grid.dataSource.remove(dataItem);
//grid.dataSource.insert(newIndex, dataItem);
//$("#medicijnenGridVolgorde").data("kendoGrid").dataSource.fetch();
// grid.dataSource.read();
grid.dataSource.refresh();
//}
}
})
return false;
}
[code] 
 
and this is the method in the controller:
 
[code]
 
public ActionResult MoveUP(int id /*MedicijnViewModel model, HttpPostedFileBase bijsluiter*/)
{
var medicijn = medicijnService.GetById(id);
Item item = medicijnService.GetById(id). medicijn.Id. .Items.Single(i => i.Id == id);
if (medicijn.Id > 0)
{
medicijn predecessor = Context.Items.Single(i => i.Index == medicijn.Id - 1);
item.Index -= 1;
predecessor.Index += 1;
//predecessor;
medicijnService.Save(medicijn);
//Context.SaveChanges();
}
return View();
}
[/code] 
 
Thank you for your help. 

Answers (2)