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); }