Exemple #1
0
        public List <TodoItem> GetUserItems()
        {
            var itemDB = new TodoItemContext("server=localhost;port=3306;database=todo;uid=sasha;password=996633");

            var result = itemDB.Items.SqlQuery("select * from todoitems").ToList <TodoItem>();

            itemDB.Dispose();

            return(result);
        }
Exemple #2
0
        public int GetHighestId()
        {
            var itemDB = new TodoItemContext("server=localhost;port=3306;database=todo;uid=sasha;password=996633");

            itemDB.Items.Add(new TodoItem(0, "", false));
            itemDB.SaveChanges();

            var result = itemDB.Items.SqlQuery("SELECT * from todoitems ORDER BY id DESC LIMIT 1").ToList <TodoItem>();

            itemDB.Dispose();

            return(result[0].Id);
        }
Exemple #3
0
        public void RemoveItems(List <TodoItem> items)
        {
            var itemDB = new TodoItemContext("server=localhost;port=3306;database=todo;uid=sasha;password=996633");

            foreach (var item in items)
            {
                var itemToRemove = itemDB.Items.SingleOrDefault(currItem => currItem.Id == item.Id);

                if (itemToRemove != null)
                {
                    itemDB.Items.Remove(itemToRemove);
                }
            }

            itemDB.SaveChanges();
            itemDB.Dispose();
        }
Exemple #4
0
        public void AddItems(List <TodoItem> items)
        {
            var itemDB = new TodoItemContext("server=localhost;port=3306;database=todo;uid=sasha;password=996633");

            foreach (var item in items)
            {
                var itemInDB = itemDB.Items.SingleOrDefault(dbItem => dbItem.Id == item.Id);

                if (null == itemInDB)
                {
                    itemDB.Items.Add(item);
                }
                else
                {
                    itemInDB.Content = item.Content;
                    itemInDB.Done    = item.Done;
                }
            }
            itemDB.SaveChanges();

            itemDB.Dispose();
        }