public VacationFunctionalGroupEmployeePlacementViewModel(VacationFunctionalGroupViewModel owner, long? employeeId)
 {
     Owner = owner;
     EmployeeId = employeeId;
     if (employeeId != null)
     { 
         Employee = Owner.Owner.Staffing.Employees.FirstOrDefault(e => e.Employee.Id == employeeId.Value);
         Owner.Owner.Staffing.Employees.CollectionChanged += (_, e) => 
         {
             if (e.OldItems != null)
             {
                 var item = e.NewItems.Cast<Staffing.EmployeeViewModel>().FirstOrDefault(e2 => e2.Employee.Id == employeeId.Value);
                 if (item != null)
                 {
                     Employee = null;
                     RaisePropertyChanged(() => Employee);
                 }
             }
             if (e.NewItems != null)
             {
                 var item = e.NewItems.Cast<Staffing.EmployeeViewModel>().FirstOrDefault(e2 => e2.Employee.Id == employeeId.Value);
                 if (item != null)
                 {
                     Employee = item;
                     RaisePropertyChanged(() => Employee);
                 }
             }
         };
     }
 }
示例#2
0
        private void OnWorkerVacationFunctionalGroupChanged(object sender, ListItemsEventArgs<VacationService.VacationFunctionalGroup> e)
        {
            if (new[] { ChangeAction.Add, ChangeAction.Change }.Contains(e.Action))
            {
                foreach (var d in e.Items)
                {
                    if (d.Id != 0)
                    {
                        var existedVacationFunctionalGroup = vacationFunctionalGroups.FirstOrDefault(l => l.Group.Id == d.Id);
                        if (existedVacationFunctionalGroup != null)
                        {
                            existedVacationFunctionalGroup.Group.CopyObjectFrom(d);
                        }
                        else
                        {
                            var vm = new VacationFunctionalGroupViewModel(d, this);
                            vm.PropertyChanged += (_, e2) => 
                            {
                                if (e2.PropertyName == nameof(vm.IsChecked))
                                {
                                    EmployeeVacationsCollectionView.Refresh();
                                }
                            };
                            vacationFunctionalGroups.Add(vm);
                        }
                    }
                }
            }
            else
            {
                foreach (var d in e.Items)
                {
                    if (d.Id != 0)
                    {
                        var existedVacationFunctionalGroup = vacationFunctionalGroups.FirstOrDefault(l => l.Group.Id == d.Id);
                        if (existedVacationFunctionalGroup != null)
                            vacationFunctionalGroups.Remove(existedVacationFunctionalGroup);
                    }
                }
            }

            OnVacationFunctionalGroupChanged?.Invoke(this, e);
        }