Пример #1
0
        public async void Login()
        {
            try
            {
                InternetConnectionHelper.GetInstance().CheckConnection();

                IsRunning = true;
                if (string.IsNullOrEmpty(this.User) || string.IsNullOrEmpty(this.Pass))
                {
                    IsRunning = false;
                    await Application.Current.MainPage.DisplayAlert("Error", "login", "Accept");

                    return;
                }

                var validateUser = await UserService.GetInstance().Login(User, Pass);

                if (validateUser.Code != (int)EnumCodeResponse.SUCCESS)
                {
                    IsRunning = false;
                    await Application.Current.MainPage.DisplayAlert("Error", validateUser.Message, "Ok");

                    return;
                }

                Pass      = string.Empty;
                IsRunning = false;

                var findUser = JsonConvert.DeserializeObject <FindUser>(validateUser.Result.ToString());
                MainViewModel.GetInstance().GetUser          = findUser;
                MainViewModel.GetInstance().ProfileViewModel = new ProfileViewModel(MainViewModel.GetInstance().GetUser);
                MainViewModel.GetInstance().HomeViewModel    = new HomeViewModel();
                MainViewModel.GetInstance().HomeViewModel.LoadTotal();

                Application.Current.MainPage = new MasterPage();
            }
            catch (ErrorResponseServerException e)
            {
                IsRunning = false;
                await App.Current.MainPage.DisplayAlert("Error", e.Message, "Aceptar");
            }
            catch (WarningResponseServerException e)
            {
                IsRunning = false;
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");
            }
            catch (NoInternetConnectionException e)
            {
                IsRunning = false;
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");
            }
            catch (Exception e)
            {
                IsRunning = false;
                await App.Current.MainPage.DisplayAlert("Error", e.Message, "Aceptar");
            }
        }
        public async void LoadCategoryList()
        {
            try
            {
                InternetConnectionHelper.GetInstance().CheckConnection();
                IsRunning = true;
                var user       = MainViewModel.GetInstance().GetUser;
                var categories = await CategoryService
                                 .GetInstance()
                                 .FindAllByUser(user.Id);

                var categories_aux = categories
                                     .Select(x => new CategoryItemSelectedViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    UserId      = x.UserId
                });
                Categories =
                    new ObservableCollection <CategoryItemSelectedViewModel>(categories_aux);
                IsRunning = false;
            }
            catch (ErrorResponseServerException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (WarningResponseServerException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (NoInternetConnectionException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Error", e.Message, "Aceptar");

                IsRunning = false;
            }
        }
Пример #3
0
        public async void LoadIncomeList()
        {
            try
            {
                InternetConnectionHelper.GetInstance().CheckConnection();
                IsRunning = true;
                var user    = MainViewModel.GetInstance().GetUser;
                var incomes = await IncomeService
                              .GetInstance()
                              .FindAllByUser(user.Id);

                var incomes_aux = incomes
                                  .Select(x => new IncomeItemSelectedViewModel
                {
                    Id     = x.Id,
                    Amount = x.Amount,
                    Date   = x.Date
                });
                Incomes =
                    new ObservableCollection <IncomeItemSelectedViewModel>(incomes_aux);
                IsRunning = false;
            }
            catch (ErrorResponseServerException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (WarningResponseServerException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (NoInternetConnectionException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Error", e.Message, "Aceptar");

                IsRunning = false;
            }
        }
        public async void LoadExpenses()
        {
            try
            {
                InternetConnectionHelper.GetInstance().CheckConnection();

                var user = MainViewModel.GetInstance().GetUser;
                IsRunning = true;
                var expenses = await ExpenseService
                               .GetInstance()
                               .FindAllByUser(user.Id);

                IsRunning = false;
                var expenses_aux = expenses.Select(x => new ExpenseItemSelectedViewModel
                {
                    Id          = x.Id,
                    Amount      = x.Amount,
                    Category    = x.Category,
                    Date        = x.Date,
                    Description = x.Description
                });
                Expenses = new ObservableCollection <ExpenseItemSelectedViewModel>(expenses_aux);
            }
            catch (ErrorResponseServerException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (WarningResponseServerException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (NoInternetConnectionException e)
            {
                await App.Current.MainPage.DisplayAlert("Advertencia", e.Message, "Aceptar");

                IsRunning = false;
            }
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Error", e.Message, "Aceptar");
            }
        }