public async Task <IEnumerable <Event> > GetEvents(bool updateFromServer = true) { if (!_connectivityService.IsConnected()) { updateFromServer = false; } /*Get events from local DB*/ if (!updateFromServer) { var eventsLocal = await _eventRepository.EnumerateAllAsync(); eventsLocal.ForEach(e => { e.Vouchers = _voucherRepository.GetListByPredicate(v => v.EventId == e.Id); }); if (eventsLocal != null) { return(eventsLocal); } } /*Get events from server*/ _uiServices.ShowLoading("Carregando seus Eventos, aguarde"); var events = await _eventPolicies.GetPolicies().ExecuteAsync(async() => { return(await _voucherApi.GetEventsAsync(_sessionManager.GetUserId(), _sessionManager.GetUserToken())); }); _uiServices.HideLoading(); /*Removing existing events from local DB*/ await _eventRepository.RemoveAllAsync(); if (events != null) { await _eventRepository.AddAllAsync(events);/*Adding the new events to local DB*/ } var vouchers = events.SelectMany(e => e.Vouchers); await _voucherRepository.RemoveAllAsync(); if (vouchers != null) { await _voucherRepository.AddAllAsync(vouchers); } return(events); }
private async void GetEventVoucherListCommandAction() { Event.Vouchers = await _voucherService.GetVouchers(Event.Id); if (Event.Vouchers != null) { await _voucherRepository.RemoveAllAsync(); await _voucherRepository.AddAllAsync(Event.Vouchers); } RaisePropertyChanged("Event"); }