Exemple #1
0
        private void ExecuteRefreshListCommand()
        {
            IsRefreshing = true;
            var collaboratorService      = new CollaboratorService();
            var phoneCongregationService = new PhoneCongregationService();
            var usefulPhoneService       = new UsefulPhoneService();

            Task.Run(async() =>
            {
                try
                {
                    UserDialogs.Instance.ShowLoading(AppSettings.WaitingText, MaskType.Black);
                    collaboratorService.CleanCollaborators();
                    usefulPhoneService.CleanUsefulPhones();
                    phoneCongregationService.CleanPhoneCongregations();
                    Collaborators      = new List <Collaborator>(await collaboratorService.GetAllCollaboratorsFromApi());
                    UsefulPhones       = new List <UsefulPhone>(await usefulPhoneService.GetAllUsefulPhonesFromApi());
                    PhoneCongregations = new List <PhoneCongregation>(await phoneCongregationService.GetAllPhonesFromApi());
                    CollaboratorsList  = ListCollaborator(string.Empty);
                    RaisePropertyChanged(nameof(Collaborators));
                    RaisePropertyChanged(nameof(UsefulPhones));
                    RaisePropertyChanged(nameof(PhoneCongregations));
                    SearchText = string.Empty;
                    UserDialogs.Instance.HideLoading();
                    DefaultToasts.Success("Dados atualizados com sucesso.");
                    IsRefreshing = false;
                }
                catch (Exception ex)
                {
                    DefaultToasts.Error(ex.Message);
                    UserDialogs.Instance.HideLoading();
                    IsRefreshing = false;
                }
            });
        }
        private async void ExecuteAcessarCommand()
        {
            try
            {
                UserDialogs.Instance.ShowLoading(AppSettings.WaitingText, MaskType.Black);
                if (string.IsNullOrEmpty(PhoneNumber) || string.IsNullOrEmpty(Code))
                {
                    if (string.IsNullOrEmpty(PhoneNumber))
                    {
                        PhoneNumberError = "Digite um número";
                    }
                    else
                    {
                        PhoneNumberError = string.Empty;
                    }
                    if (string.IsNullOrEmpty(Code))
                    {
                        CodeError = "Digite o código";
                    }
                    else
                    {
                        CodeError = string.Empty;
                    }
                }
                else
                {
                    UserDialogs.Instance.ShowLoading(AppSettings.WaitingText, MaskType.Black);

                    ApiReturn loginReturn = await new UserService().Login(PhoneNumber, Code);

                    if (loginReturn.Success)
                    {
                        UserDialogs.Instance.HideLoading();
                        await _navigationService.NavigateAsync("myapp:///NavigationPage/" + AppSettings.HomeApplication);
                    }
                    else
                    {
                        DefaultToasts.Error(loginReturn.Message);
                    }

                    UserDialogs.Instance.HideLoading();
                }
            }
            catch (Exception ex)
            {
                DefaultToasts.Error(ex.Message);
            }
            finally
            {
                UserDialogs.Instance.HideLoading();
            }
        }
Exemple #3
0
        public MainPrincipalViewModel(INavigationService navigationService) : base(navigationService)
        {
            Title = "Agenda CCB " + DateTime.Now.Year;

            ShowCollaboratorCommand = new Command <Collaborator>(ExecuteShowCategoriaCommand);
            RefreshListCommand      = new Command(ExecuteRefreshListCommand);
            Task.Run(async() =>
            {
                try
                {
                    UserDialogs.Instance.ShowLoading(AppSettings.WaitingText, MaskType.Black);
                    Collaborators      = new List <Collaborator>(await LoadCollaborators());
                    UsefulPhones       = new List <UsefulPhone>(await LoadUsefulPhones());
                    PhoneCongregations = new List <PhoneCongregation>(await LoadPhoneCongregations());
                    CollaboratorsList  = ListCollaborator(string.Empty);
                    RaisePropertyChanged(nameof(Collaborators));
                    RaisePropertyChanged(nameof(UsefulPhones));
                    RaisePropertyChanged(nameof(PhoneCongregations));
                    UserDialogs.Instance.HideLoading();
                }

                catch (Exception ex)
                {
                    DefaultToasts.Error(ex.Message);
                    UserDialogs.Instance.HideLoading();
                }
            });

            this.ItemTappedCommand = new Command(async item =>
            {
                var collaboratorItem = (Collaborator)item;
                var navigationParams = new NavigationParameters
                {
                    { "Collaborator", collaboratorItem }
                };

                CanNavigate = false;
                await _navigationService.NavigateAsync("CollaboratorPage", navigationParams);
                CanNavigate = true;
            }, canExecute: (x) => CanNavigate);

            this.UsefulListTappedCommand = new Command(item =>
            {
                var usefulPhone = (UsefulPhone)item;
                Device.OpenUri(new Uri(string.Format("tel:{0}", usefulPhone.PhoneNumber)));
            });

            this.PhoneCongregationListTappedCommand = new Command(async item =>
            {
                var phoneCongregationItem = (PhoneCongregation)item;
                var navigationParams      = new NavigationParameters
                {
                    { "PhoneCongregation", phoneCongregationItem }
                };

                CanNavigate = false;
                await _navigationService.NavigateAsync("CongregationPhonePage", navigationParams);
                CanNavigate = true;
            }, canExecute: (x) => CanNavigate);

            this.SearchCommand = new Command(item =>
            {
                CollaboratorsList = ListCollaborator(SearchText);
            });
        }