private void CreateFakeStudents() { if (Database.CountStudents() > 0) return; Student gabe = new Student() { Name = "Gabe", LastName = "Aul", Email = "*****@*****.**", PhoneNumber = "5255400331122" }; Student satya = new Student() { Name = "Satya", LastName = "Nadella", Email = "*****@*****.**", PhoneNumber = "5255400331122" }; Student bill = new Student() { Name = "Bill", LastName = "Gates", Email = "*****@*****.**", PhoneNumber = "5255400331122" }; Database.AddOrUpdateStudent(gabe); Database.AddOrUpdateStudent(satya); Database.AddOrUpdateStudent(bill); gabe = Database.SearchStudentByEmail(gabe.Email); satya = Database.SearchStudentByEmail(satya.Email); bill = Database.SearchStudentByEmail(bill.Email); List<Grade> grades = new List<Grade>(); grades.Add(new Grade() { Class = "Math", Result = new Random().Next(10).ToString(), }); grades.Add(new Grade() { Class = "Spanish", Result = new Random().Next(10).ToString(), }); grades.Add(new Grade() { Class = "Science", Result = new Random().Next(10).ToString(), }); grades.Add(new Grade() { Class = "Xamarin", Result = new Random().Next(10).ToString(), }); grades.Add(new Grade() { Class = "Windows", Result = new Random().Next(10).ToString(), }); Database.AddAllGradesToStudent(grades, gabe.Id); Database.AddAllGradesToStudent(grades, satya.Id); Database.AddAllGradesToStudent(grades, bill.Id); }
/// <summary> /// With a Student Id == 0, will create a new student /// </summary> /// <param name="student"></param> public static void AddOrUpdateStudent(Student student) { // Create a new connection using (var db = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath)) { if (student.Id == 0) { // New db.Insert(student); } else { // Update db.Update(student); } } }