Exemple #1
0
        private void buttonPickDate_Click(object sender, EventArgs e)
        {
            Action <DateTime> pickToDoListForDateAction = (pickedDate) =>
            {
                //Pick date and find 'ToDo List' for that date
                var listByDate = _toDoListDao.GetOneByDate(pickedDate);

                //If 'ToDo List' doesn't exist, create new one
                if (listByDate == null)
                {
                    var newList = _toDoListDao.Insert(ToDoList.New(pickedDate));
                    listByDate = newList;
                    _toDoListService.AddListToCache(listByDate);
                }

                // Create model for 'ToDoList' and display it
                flowLayoutPanel1.Controls.Clear();
                var listByDateModel = new ToDoListModel(listByDate);
                _currentToDoList = listByDateModel;

                var toDoListControl = new ToDoListControl(listByDateModel, _toDoListService, _toDoListDao, _toDoTaskDao);
                flowLayoutPanel1.Controls.Add(toDoListControl);
            };

            var datePickerForm = new DatePickerForm(pickToDoListForDateAction);

            datePickerForm.Show();
        }
        public IList <ToDoList> PopulateToDoListCache()
        {
            _toDoListCache = _toDoListDao.GetAll();

            // If there is no 'To Do List' avaliable, create first one
            if (_toDoListCache?.Any() != true)
            {
                var firstToDoList = _toDoListDao.Insert(ToDoList.New(DateTime.Now.Date));
                _toDoListCache.Add(firstToDoList);
                _currentListCache = firstToDoList;
                return(_toDoListCache);
            }

            _currentListCache = _toDoListCache
                                .FirstOrDefault(tdl => tdl.Date.ToShortDateString() == DateTime.Now.ToShortDateString());
            return(_toDoListCache);
        }