public void InsertTrainer() { 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); string sub; Console.WriteLine("If you want to set subject for this trainer, press Y. Otherwise no subject will be inserted."); string answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type subject:"); sub = ConsoleRead.SetVarchar(50); } else { sub = null; } Trainer tr = new Trainer() { firstName = fname, lastName = sname, subject = sub }; dbContext.Trainers.Add(tr); dbContext.SaveChanges(); }
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(); }
public void InsertAssignment() { string _title; Console.WriteLine("If you want to set title for this assignment, press Y. Otherwise no title will be inserted."); string answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type title:"); _title = ConsoleRead.SetVarchar(50); } else { _title = null; } string desc; Console.WriteLine("If you want to set description for this assignment, press Y. Otherwise no description will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type description:"); desc = ConsoleRead.SetVarchar(500); } else { desc = null; } Date?subdt; Console.WriteLine("If you want to set submission deadline for this assignment, press Y. Otherwise no deadline will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type deadline date and time. The date and time must be after the current:"); subdt = ConsoleRead.SetDateTime(); } else { subdt = null; } int?oral; Console.WriteLine("If you want to set maximum oral mark for this assignment, press Y. Otherwise no oral mark will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type maximum possible oral mark:"); oral = ConsoleRead.SetInt(true); } else { oral = null; } int?total; Console.WriteLine("If you want to set maximum total mark for this assignment, press Y. Otherwise no total mark will be inserted."); answer = Console.ReadLine().ToLower(); if (answer == "y" || answer == "yes") { Console.WriteLine("Type maximum possible total mark:"); total = ConsoleRead.SetInt(true); } else { total = null; } Assignment ass = new Assignment() { title = _title, description = desc.Substring(0, 49), subDateTime = subdt, oralMark = oral, totalMark = total }; dbContext.Assignments.Add(ass); dbContext.SaveChanges(); }