public static void AddTeachers(Teacher Teacher) { using (var Model = new SchoolVolunteerModel()) { Model.Teachers.Add(Teacher); Model.SaveChanges(); // database connection terminated } }
/// <summary> /// Print the family details /// </summary> public static void DisplayFamily() { using (var model = new SchoolVolunteerModel()) { foreach (var family in model.Families) { Console.WriteLine("FamilyName: {0}\n,MothersName: {1}\n,FathersName: {2}\n,Child1 :{3}\n,Child2: {4}\n\n", family.FamilyName, family.MothersName, family.FathersName, family.Child1, family.Child2); } } }
//public string Kids { get; set; } #endregion #region Methods /// <summary> /// adding each family to the family list with this method /// </summary> /// <param name="family"></param> /// #region methods for Family public static void AddFamily(Family family, Volunteer volunteer, ClassRoom classroom) { using (var Model = new SchoolVolunteerModel()) { //Model is the connection name and we are creating an instance of the database connection //"using " is used to end the scope of the Datebase (closing the db) Model.Families.Add(family); Model.Volunteers.Add(volunteer); // Model.Teachers.Add(Teacher); Model.ClassRoom.Add(classroom); Model.SaveChanges(); }//by this time the database connection is terminated }