public virtual void CreateTask(Task task)
        {
            var context = new TaskDataContext();

            context.AddObject(TaskDataContext.TaskTable, task.ToRow());
            context.SaveChanges();
        }
        public virtual TaskList CreateList(string name, bool publicList)
        {
            var context = new TaskDataContext();
            var list = new TaskList { Name = name, IsPublic = publicList };
            context.AddObject(TaskDataContext.TaskListTable, list.ToRow());
            context.SaveChanges();

            return list;
        }
        public virtual void DeleteTask(string listId, string taskId)
        {
            var context = new TaskDataContext();

            var task = context.Tasks
                .Where(t => t.PartitionKey == listId && t.RowKey == taskId && true)
                .SingleOrDefault();

            if (task != null)
            {
                context.DeleteObject(task);
                context.SaveChanges();
            }
        }
        public virtual void DeleteList(string listId)
        {
            var context = new TaskDataContext();

            var list = context.TaskLists
               .Where(t => t.RowKey == listId && t.PartitionKey == listId.Substring(0, 1) && true)
               .SingleOrDefault();

            if (list != null)
            {
                var tasks = context.Tasks
                    .Where(t => t.PartitionKey == listId);

                foreach (TaskRow task in tasks)
                {
                    context.DeleteObject(task);
                }

                context.DeleteObject(list);
                context.SaveChanges();
            }
        }
        public virtual Task GetTask(string taskId, string listId)
        {
            var context = new TaskDataContext();

            var task = context.Tasks
                .Where(t => t.RowKey == taskId && t.PartitionKey == listId && true)
                .ToModel()
                .SingleOrDefault();

            return task;
        }
 public virtual void CreateTables()
 {
     var context = new TaskDataContext();
     context.CreateTables();
 }
        public virtual void UpdateTask(Task task)
        {
            var context = new TaskDataContext();
            var taskRow = task.ToRow();

            context.AttachTo(TaskDataContext.TaskTable, taskRow, "*");
            context.UpdateObject(taskRow);
            context.SaveChanges();
        }
        public virtual void UpdateList(TaskList list)
        {
            var context = new TaskDataContext();
            var taskListRow = list.ToRow();

            context.AttachTo(TaskDataContext.TaskListTable, taskListRow, "*");
            context.UpdateObject(taskListRow);
            context.SaveChanges();
        }
 public virtual bool TablesExist()
 {
     var context = new TaskDataContext();
     return context.IsTablesCreated;
 }
 public virtual PagedTaskSource GetTasks(string listId, int pageSize, string nextPartition, string nextRowKey)
 {
     var context = new TaskDataContext();
     return new PagedTaskSource(context.Tasks.Where(t => t.ListId == listId), nextPartition, nextRowKey, pageSize);
 }
        public virtual IEnumerable<TaskList> GetTaskLists(bool includePrivate)
        {
            var context = new TaskDataContext();

            var lists = context.TaskLists
                .Where(t => t.IsPublic == true || t.IsPublic != includePrivate);

            return lists.ToModel();
        }
        public virtual TaskList GetTaskList(string listId)
        {
            var context = new TaskDataContext();

            if (this.TablesExist())
            {
                var list = context.TaskLists
                .Where(t => t.RowKey == listId && t.PartitionKey == listId.Substring(0, 1) && true)
                .ToModel()
                .SingleOrDefault();

                return list;
            }

            return null;
        }