I have the following code:
jobsToShiftUp.AddRange(PresentationManager.Instance.ScheduleViewSource.Where(o => o.Resources.First().ResourceName == criticalJob.Resources.First().ResourceName && ((o.Start >= criticalJob.Start) || (o.Start < criticalJob.Start && o.End > criticalJob.Start)) && !o.JobGuid.Equals(((Job)state.DraggedAppointments.First()).JobGuid) && GetWeekNumber(o.Start) == GetWeekNumber(criticalJob.Start)));
jobsToShiftUp = jobsToShiftUp.OrderBy(o => o.Start).ToList();
TimeSpan timeToShift = criticalJob.End - jobsToShiftUp.First().Start;
foreach (Job job in jobsToShiftUp)
{
if (jobsToShiftUp.IndexOf(job) == 0)
{
((ObservableCollection<Job>)state.DestinationAppointmentsSource).Single(o => o.JobGuid.Equals(job.JobGuid)).Start += timeToShift;
((ObservableCollection<Job>)state.DestinationAppointmentsSource).Single(o => o.JobGuid.Equals(job.JobGuid)).End += timeToShift;
……
The last two lines (increasing the start and end properties of the jobs) affects both the state.destinationappointmentssource list AND the jobsToShiftUp list (i.e. it affects the job object currently being referenced in the foreach loop). I can’t think why it would affect the jobsToShiftUp list at all!?
I think both object have same reference.
So
jobsToShiftUpcollection andstate.DestinationAppointmentsSourcemight both have some same reference and updating the one reflecting in another.You can use cloning (deep copy) to avoid this .