public void InsertStudent() { Console.WriteLine("Type a first name between 1 and 50 characters:"); string fname = ConsoleRead.SetVarchar(50, 1); Console.WriteLine("Type a last name between 1 and 50 characters:"); string sname = ConsoleRead.SetVarchar(50, 1); Console.WriteLine("Type a valid date of birth. The date must be before today:"); Date birthdate = ConsoleRead.SetDate(); double?fees; Console.WriteLine("If you want to set tuition fees for this student, press Y. Otherwise no fees will be inserted."); string answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type tuition fees for the student:"); fees = ConsoleRead.SetDouble(true); } else { fees = null; } Student std = new Student() { firstName = fname, lastName = sname, dateOfBirth = birthdate, tuitionFees = (decimal?)fees }; dbContext.Students.Add(std); dbContext.SaveChanges(); }
public void InsertCourse() { string _title = ConsoleRead.SetVarchar(50); string _stream; Console.WriteLine("If you want to set stream for this course, press Y. Otherwise no stream will be inserted."); string answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type stream:"); _stream = ConsoleRead.SetVarchar(50); } else { _stream = null; } string _type; Console.WriteLine("If you want to set type for this course, press Y. Otherwise no type will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type type:"); _type = ConsoleRead.SetVarchar(50); } else { _type = null; } Date?start; Console.WriteLine("If you want to set start date for this course, press Y. Otherwise no start date will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type start date. Note that you will have to assign a future date:"); start = ConsoleRead.SetDate(true); } else { start = null; } Date?end; Console.WriteLine("If you want to set end date for this course, press Y. Otherwise no end date will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type end date. Note that you will have to assign a future date:"); end = ConsoleRead.SetDate(true); } else { end = null; } Course cr = new Course() { title = _title, stream = _stream, type = _type, start_date = start, end_date = end }; dbContext.Courses.Add(cr); dbContext.SaveChanges(); }