public void CreateMethod() { //If any of the properties are null, there was a problem loading the variables if (ClassName == null && DateDue == null && Importance == null) { throw new InvalidOperationException($"{nameof(ClassName)}, {nameof(DateDue)} or {nameof(Importance)} is null"); } DateTime formatDateDue; try { //Convert the date String into type DateTime formatDateDue = DateTime.Parse(DateDue); } catch (Exception ex) { //String was in a incorrect format throw new FormatException("The Date Due was in a bad format", ex); } //Retrieves the letter from the end of the Course, this determines which semester the class is in var charArray = ClassName.ToArray(); var getSemester = charArray.Last(); string semester; switch (getSemester) { case 'a': semester = "1st"; break; case 'b': semester = "2nd"; break; default: semester = "NA"; break; } var addClass = new DueItem() { Class = ClassName, Semester = semester, Date_Due = formatDateDue, Importance = Importance, Description = Description }; using (databaseConnection = new CoursesEntities1()) { databaseConnection.DueItems.Add(addClass); databaseConnection.SaveChanges(); } Refresh(); }