public bool AddPatientPrivateVisit(Patient p, DateTime d) { //Private health care - patient chooses appointment date. We pospone appointments of all the the rest patients (and then - we text them). var patientsToMove = patients.Where(c => c.Key >= d).ToList(); patients.Add(new KeyValuePair <DateTime, Patient>(d, p)); patients.Sort((x, y) => x.Key.CompareTo(y.Key)); List <KeyValuePair <DateTime, Patient> > temp = new List <KeyValuePair <DateTime, Patient> >(); foreach (var pa in patientsToMove) { var newDate = pa.Key.AddMinutes(30); var pToMove = pa.Value; patients.Remove(pa); temp.Add(new KeyValuePair <DateTime, Patient>(newDate, pToMove)); MessagesManager.SendSMS(pa.Value, newDate); } patients.AddRange(temp); patients.Sort((x, y) => x.Key.CompareTo(y.Key)); Console.WriteLine($"Registered on {d} patient: {p.FirstName} {p.LastName}"); return(true); }