public async Task <User> LogUserAsync(LoginCredentials login) { _uiServices.ShowLoading("Login em andamento, aguarde..."); return(await _policies.GetPolicies().ExecuteAsync(async() => { if (!_connectivityService.IsConnected()) { throw new NoInternetException(); } login.Email = login.Email.Trim(); var user = await _api.LogUserAsync(login); _uiServices.HideLoading(); if (user == null) { throw new UserNotFoundException(); } await _sessionManager.StartSessionAsync(user); _uiServices.HideLoading(); return user; })); }
public async Task RefreshAsync() { // Check connectivity if (!connectivityService.IsConnected()) { return; } IsLoading = true; // Update photo with detailed information Photo = await photoService.GetPhotoDetails(Photo.Id); // Check if photo is a current user's one try { var currentUser = await photoService.GetCurrentUser(); if (currentUser.UserId == Photo.User.UserId) { IsCurrentUsersPhoto = true; } else { IsCurrentUsersPhoto = false; } } catch (UnauthorizedException) { IsCurrentUsersPhoto = false; } IsLoading = false; }
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); }
public async Task InitAsync() { // Check connectivity if (!connectivityService.IsConnected()) { return; } // Load available categories var categories = await photoService.GetCategories(); CategoryOptions.ReplaceRange(categories); }
public async Task RefreshAsync(bool force = false) { if ((IsLoaded || IsLoading) && !force) { return; } IsLoading = true; // Check connectivity if (!connectivityService.IsConnected()) { IsLoading = false; return; } if (categoryId != null) { var photosForCategory = await photoService.GetPhotosForCategoryId(categoryId); Photos.ReplaceRange(photosForCategory.Items); // TODO: Implement pagination, as this only loads photos for the fist page. } IsLoaded = true; IsLoading = false; }
public async Task InitAsync() { // Check connectivity if (!connectivityService.IsConnected()) { return; } try { var currentUser = await photoService.GetCurrentUser(); IsLoggedIn = true; await SetupUser(currentUser); } catch (UnauthorizedException) { IsLoggedIn = false; } }
public override async Task Initialize() { this.TitleText = Constants.APP_NAME; this.SubTitleText = Constants.APP_SUB_NAME; this.ErrorButtonText = Constants.ERROR_BUTTON_TEXT; this.ProgressBarTitle = Constants.PROGRESS_BAR_TITLE; IsConnected = _connectivityService.IsConnected(); this.ErrorMessage = (!IsConnected ? Constants.CONNECT_INTERNET_MSG : String.Empty); }
public async Task RefreshAsync(bool force = false) { // Check connectivity if (!connectivityService.IsConnected()) { await ShowNoConnectionDialog(dialogService); return; } // Check if ViewModel is already loaded or refreshing if (IsLoading || (IsLoaded && !force)) { return; } IsLoading = true; // Don't use placeholders when PullToRefresh is used //if (!force) //{ // // Get Mock Data to show placeholders // HeroImages.ReplaceRange(MockData.GetHeroImages()); // //TopCategories.ReplaceRange(MockData.GetTopCategories()); // TopCategories = new ObservableRangeCollection<GroupedCategoryPreview>(MockData.GetTopCategories()); //} // Get current user try { // Try to restore user credentials if (AzureAppService.Current.CurrentUser == null) { await photoService.RestoreSignInStatusAsync(); } CurrentUser = await photoService.GetCurrentUser(); } catch (Exception ex) { if (ex is UnauthorizedException || ex is ServiceException) { // User not logged in yet CurrentUser = null; } else { throw; } } // Load hero images var heroes = await photoService.GetHeroImages(5); HeroImages.ReplaceRange(heroes); // Load categories var topCat = await photoService.GetTopCategories(6); var grouped = from category in topCat group category by category.Name into categoryGroup select new GroupedCategoryPreview(categoryGroup.First()?.PhotoThumbnails, categoryGroup.Key, categoryGroup.Key.Substring(0, 1), categoryGroup.FirstOrDefault()); //HACK: Re-initializing because FlowListView crashes when Replacing lists at the moment. TopCategories = new ObservableRangeCollection <GroupedCategoryPreview>(grouped); //TopCategories.ReplaceRange(grouped); // Check if loading went right IsLoaded = HeroImages.Count > 0 || TopCategories.Count > 0; IsLoading = false; }