Пример #1
0
 public Db()
 {
     AppDomain.CurrentDomain.SetData("DataDirectory", Path.GetFullPath(@"..\..\..\TodoApp\App_Data"));
        db = new TodoItemContext();
 }
Пример #2
0
        /// <summary>
        /// Initiate a new todo list for new user
        /// </summary>
        /// <param name="userName"></param>
        private static void InitiateDatabaseForNewUser(string userName)
        {
            TodoItemContext db = new TodoItemContext();
            TodoList todoList = new TodoList();
            todoList.UserId = userName;
            todoList.Title = "My Todo List #1";
            todoList.Todos = new List<TodoItem>();
            db.TodoLists.Add(todoList);
            db.SaveChanges();

            todoList.Todos.Add(new TodoItem() { Title = "Todo item #1", TodoListId = todoList.TodoListId, IsDone = false });
            todoList.Todos.Add(new TodoItem() { Title = "Todo item #2", TodoListId = todoList.TodoListId, IsDone = false });
            db.SaveChanges();
        }