private static List <Week> SortTasks(List <Task> tasks) { List <Day> days = new List <Day>(); List <Week> weeks = new List <Week>(); foreach (Task t in tasks) { Day matchingDay = days.Find(d => d.Date.Date == t.DueDatetime.Date); if (matchingDay == null) { days.Add(new Day(t.DueDatetime.Date, new List <Task>(new Task[] { t }))); } else { matchingDay.AddTask(t); } } foreach (Day d in days) { int weekNum = DateService.GetWeekNumber(d.Date); Week matchingWeek = weeks.Find(w => w.WeekNumber == weekNum); if (matchingWeek == null) { weeks.Add(new Week(weekNum, new List <Day>(new Day[] { d }))); } else { matchingWeek.AddDay(d); } } return(weeks); }
public static void DeleteTask(Task t) { int weekNum = DateService.GetWeekNumber(t.DueDatetime); User.Planner.Weeks.Find(w => w.WeekNumber == weekNum).Days.Find(d => d.Date.Date == t.DueDatetime.Date).Tasks.Remove(t); SaveTasks(); }
public MyPlanner() { InitializeComponent(); Planner = User.Planner; WeekNum = DateService.GetWeekNumber(DateTime.Now); DisplayThisWeeksTasks(); }
private void SaveTask(object sender, RoutedEventArgs e) { string type = ""; Priority priority = Priority.Low; DateTime due = DateTime.Now; string title = tblkTitle.Text; string description = tblkDescription.Text; try { type = comboTaskType.SelectedItem.ToString(); priority = GetPriority(); } catch (NullReferenceException err) { Toastr.Warning("Warning", "Please choose an option in all dropdown menus"); return; } try { due = dueDate.SelectedDate.Value.Date; due = due.Date + new TimeSpan(23, 59, 59); } catch (InvalidOperationException err) { Toastr.Warning("Warning", "Please select a valid date"); return; } Task newTask = CreateNewTask(type, title, description, priority, due); if (newTask != null) { int weekNumber = DateService.GetWeekNumber(newTask.DueDatetime); SaveNewTask(newTask, weekNumber); NavigationService.Navigate(new MyPlanner()); } else { Toastr.Error("Error", "Failed to create new task"); } }