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); }
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(); }
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(); }