Exemplo n.º 1
0
        /// <summary>
        /// This function is loading daily task to listBox
        /// </summary>
        private void SetUpMyListBox()
        {
            myTasks = new List <ToDoTaskModel>();
            listBoxDailyTasks.Items.Clear();
            try
            {
                using (var dbContex = new ToDoAppDbContext())
                {
                    dayRepository      = new DayRepository(dbContex);
                    toDoTaskRepository = new ToDoTaskRepository(dbContex);
                    DayModel item = (DayModel)comboBoxDates.SelectedItem;

                    var day        = dayRepository.GetByDate(dayMapper.Map(item).Date);
                    var dailyTasks = toDoTaskRepository.GetByDate(day).AsParallel();
                    if (dailyTasks != null)
                    {
                        listBoxDailyTasks.DisplayMember = "Name";
                        foreach (var task in dailyTasks)
                        {
                            var taskModel = toDoTaskMapper.Map(task);
                            listBoxDailyTasks.Items.Add(taskModel);
                            myTasks.Add(taskModel);
                        }
                        listBoxDailyTasks.Update();
                        listBoxDailyTasks.SelectedItem = listBoxDailyTasks.Items[0];
                        FindNextTask.GetNextTask(myTasks, ref labelNextTaskValue);
                    }
                }
            }catch (Exception e)
            {
                MessageBox.Show("There are no tasks for the selected day");
            }
        }
Exemplo n.º 2
0
 public void DeleteSelectedItem(DayRepository dayRepository, ToDoTaskRepository toDoTaskRepository, ListBox listBoxDailyTasks, ToDoTaskMapper toDoTaskMapper)
 {
     using (var dbContex = new ToDoAppDbContext())
     {
         dayRepository      = new DayRepository(dbContex);
         toDoTaskRepository = new ToDoTaskRepository(dbContex);
         var itemToDelete = toDoTaskRepository.GetByName(toDoTaskMapper.Map((ToDoTaskModel)listBoxDailyTasks.SelectedItem).Name);
         if (itemToDelete != null)
         {
             dbContex.DailyTasks.Remove(itemToDelete);
             dbContex.SaveChanges();
             MessageBox.Show("Task was deleted.");
         }
         else
         {
             MessageBox.Show("There is no task to delete.");
         }
     }
 }