예제 #1
0
        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"
            });
        }
예제 #2
0
        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" };
        }