public ActionResult Sort() { string ids = Request.Form["ids"]; string[] sorted = ids.Split(','); List <long> l = new List <long>(); foreach (string id in sorted) { long temp = 0; if (long.TryParse(id.Replace("item", ""), out temp)) { l.Add(temp); } } long accountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); List <ToDoItem> items = repository.FindByAccountId(accountId); repository.AutoSubmit = false; int currentSort = 1; foreach (long itemid in l) { foreach (ToDoItem item in items) { if (item.Id == itemid) { item.SortOrder = currentSort; currentSort += 1; repository.Update(item); } } } repository.SubmitChanges(); return(new JsonResult() { Data = "result:true" }); }
// // GET: /ToDo/ public ActionResult Index() { bool failed = false; if (Request.QueryString["failed"] != null) { failed = true; } List<ToDoItem> items = new List<ToDoItem>(); UserAccount adminUser = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp); if (adminUser != null) { ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); items = repository.FindByAccountId(adminUser.Id); } FlashFailure("Failed to Create Task. Please Try Again."); return View(items); }
// // GET: /ToDo/ public ActionResult Index() { bool failed = false; if (Request.QueryString["failed"] != null) { failed = true; } List <ToDoItem> items = new List <ToDoItem>(); UserAccount adminUser = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp); if (adminUser != null) { ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); items = repository.FindByAccountId(adminUser.Id); } FlashFailure("Failed to Create Task. Please Try Again."); return(View(items)); }
public ActionResult Sort() { string ids = Request.Form["ids"]; string[] sorted = ids.Split(','); List<long> l = new List<long>(); foreach (string id in sorted) { long temp = 0; if (long.TryParse(id.Replace("item",""),out temp)) { l.Add(temp); } } long accountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); List<ToDoItem> items = repository.FindByAccountId(accountId); repository.AutoSubmit = false; int currentSort = 1; foreach (long itemid in l) { foreach (ToDoItem item in items) { if (item.Id == itemid ) { item.SortOrder = currentSort; currentSort += 1; repository.Update(item); } } } repository.SubmitChanges(); return new JsonResult() { Data = "result:true" }; }