Esempio n. 1
0
        public ActionResult Reorder(int userListId, string serializedItems)
        {
            try {
                // Parse serialized items
                var pattern = @"item\[\]=(\d+)";
                var matches = Regex.Matches(serializedItems, pattern);

                // Get the new order of serialized items
                var order = new int[matches.Count];
                var index = 0;
                foreach (Match match in matches)
                    order[index++] = Int32.Parse(match.Groups[1].Value);

                // Update the list
                var list = UserListRepository.Instance.FindUserList(userListId);
                var newList = new UserList() { Url = list.Url, Name = list.Name };
                for (int i = 0; i < order.Length; i++)
                    newList.UserListItems.Add(list.UserListItems[order[i]]);
                UserListRepository.Instance.UpdateUserList(newList);
            } catch {
                //
                // TODO: Add error handler
                //
            }

            WebSocketHandler.Instance.NotifyAllClients(NotificationType.ListChanged);

            return new JsonResult();
        }
Esempio n. 2
0
        public ActionResult CreateList()
        {
            var url = Guid.NewGuid().ToString().Substring(0, 8).ToUpper();
            var list = new UserList() { Url = url };

            UserListRepository.Instance.AddUserList(list);

            return RedirectToRoute("List", new { url = list.Url });
        }
Esempio n. 3
0
 public void AddUserList(UserList list)
 {
     lock (_syncRoot) {
         using (var db = new InstantListContext()) {
             db.UserLists.Add(list);
             db.SaveChanges();
         }
     }
 }
Esempio n. 4
0
        public void UpdateUserList(UserList list)
        {
            lock (_syncRoot) {
                using (var db = new InstantListContext()) {
                    var query = from userList in db.UserLists
                                where userList.UserListId == list.UserListId
                                select userList;

                    if (query.Count() != 0) {
                        var oldList = query.FirstOrDefault();
                        db.UserLists.Remove(oldList);
                        db.UserLists.Add(list);
                        db.SaveChanges();
                    }
                }
            }
        }
Esempio n. 5
0
 public UserListViewModel(UserList list)
 {
     UserList = list;
 }