public async Task LoadShiftGroupingAsync() { IEnumerable <ShiftGrouping> grouping = new ShiftGrouping[0]; var task = Task.Run(() => { lock ( _lock ) { try { grouping = _dbContext.GetShiftGrouping().Select(s => new ShiftGrouping(s.shift, s.appointments)).ToArray(); } catch (Exception ex) { grouping = new ShiftGrouping[0]; } } }); await task; lock ( _lock ) { if (_shiftGroupingCollection.Any()) { _shiftGroupingCollection.Clear(); } foreach (var shiftGrouping in grouping) { _shiftGroupingCollection.Add(shiftGrouping); } } }
public ShiftGroupingViewModel(ShiftGrouping shiftGrouping, ReadOnlyObservableCollection <FilterViewModel> filters) { ShiftGrouping = shiftGrouping ?? throw new ArgumentNullException(nameof(shiftGrouping), @"ShiftGroupingVmCollection cannot be null."); _filterVmCollection = filters ?? throw new ArgumentNullException(nameof(filters), @"filters cannot be null."); _appointmentGroupingVmCollection = new ObservableCollection <AppointmentGroupingViewModel>( shiftGrouping.Appointments .Select(a => { var agvm = new AppointmentGroupingViewModel(a, _filterVmCollection); agvm.PropertyChanged += OnIsModifyChanged; return(agvm); }) ); AppointmentGroupingVmCollection = _appointmentGroupingVmCollection.Where(AppointmentGroupingPredicate).ToArray(); }