public void AddTimeslot(TimeSlot slot) { using (GymContext db = new GymContext()) { try { // add and save db.TimeSlots.Add(slot); db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
public void AddTrainer(Trainer trainer) { using (GymContext db = new GymContext()) { try { // add and save db.Trainers.Add(trainer); db.SaveChanges(); // navigation properties updated on both sides } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
// print trainer and their timeslots public List <Trainer> DoTrainerQuery() { using (GymContext db = new GymContext()) { List <Trainer> trainerList = new List <Trainer>(); var trainers = db.Trainers.OrderBy(l => l.ID).Select(l => new Trainer { ID = l.ID, TrainerName = l.TrainerName, Phone = l.Phone, Rating = l.Rating, Email = l.Email, Gender = l.Gender, Price = l.Price, Timeslots = l.Timeslots }); foreach (var trainer in trainers) { trainerList.Add(trainer); } Console.WriteLine("\nTrainers:"); return(trainerList); } }