Esempio n. 1
0
        public static bool UpdateList(LAList list)
        {
            bool success = false;
            var  dbList  = db.LALists.Find(list.ID);

            if (list != null)
            {
                if (list.Name != null && list.LAListItems != null)
                {
                    if (list.LAListItems.Contains(null))
                    {
                        list.LAListItems.Remove(null);
                    }
                    db.Entry(dbList).CurrentValues.SetValues(list);
                    db.Entry(dbList).State = EntityState.Modified;

                    foreach (var listItem in list.LAListItems)
                    {
                        if (listItem != null)
                        {
                            var dbListItem = db.LAListItems.Find(listItem.ID);
                            db.Entry(dbListItem).CurrentValues.SetValues(listItem);
                            db.Entry(dbListItem).State = EntityState.Modified;
                        }
                    }

                    db.SaveChanges();

                    success = true;
                }
            }

            return(success);
        }
Esempio n. 2
0
        public bool UpdateList(int listId, string newName)
        {
            var success = false;

            if (newName != null)
            {
                var updatedList = db.LALists.Where(e => e.ID == listId).FirstOrDefault();

                if (updatedList != null)
                {
                    updatedList.Name            = newName;
                    db.Entry(updatedList).State = EntityState.Modified;
                    db.SaveChanges();

                    success = true;
                }
            }

            return(success);
        }