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"); } }
private Task CreateNewTask(string type, string title, string description, Priority priority, DateTime due) { if (title.Length < 3) { Toastr.Warning("Warning", "Title length is too short"); return(null); } if (description.Length < 10) { Toastr.Warning("Warning", "Description length is too short."); return(null); } if (!DateService.DateAfterToday(due)) { Toastr.Warning("Warning", "The due date must be in the future."); return(null); } Task newTask = null; Toastr.TurnOffNotifications(); // Prevent multiple 'update' notifications DateTime now = DateTime.Now; switch (type) { case "Assignment": string subject = tbxSubject.Text; int percentage = int.Parse(tbxPercentage.Text); newTask = new AssignmentTask(title, description, priority, due, now, subject, percentage); break; case "Exam": string subjectExam = tbxSubjectExam.Text; string materials = tbxMaterials.Text; int percentageExam = int.Parse(tbxPercentExam.Text); newTask = new ExamTask(title, description, priority, due, now, subjectExam, percentageExam, new List <string>(materials.Split(','))); break; case "Event": string location = tbxLocation.Text; newTask = new EventTask(title, description, priority, due, now, location); break; case "Payment": decimal amount = decimal.Parse(tbxAmount.Text); newTask = new PaymentTask(title, description, priority, due, now, amount); break; default: Toastr.Error("Error", "Invalid task type."); break; } Toastr.TurnOnNotifications(); if (newTask != null) { Toastr.Success("Created", "The '" + title + "' task has been created"); } return(newTask); }