コード例 #1
0
        public MainViewModel()
        {
            //Singleton
            instance = this;

            //Create  observable collections
            Menu              = new ObservableCollection <MenuItemViewModel>();
            Customers         = new ObservableCollection <CustomerItemViewModel>();
            Properties        = new ObservableCollection <PropertyItemViewModel>();
            navigationService = new NavigationService();

            //Create views
            CurrentCustomer = new CustomerItemViewModel(0);

            NewCustomer = new CustomerItemViewModel(0);

            NewLogin = new LoginItemViewModel();

            CurrentProperty = new PropertyItemViewModel(0);

            NewProperty = new PropertyItemViewModel(0);
            //Insert services
            apiService = new ApiService();

            dataService = new DataService();

            netService = new NetService();

            //Load data
            LoadMenu();

            LoadCustomers();

            LoadProperties();
        }
コード例 #2
0
        private async void Login()
        {
            //Validations
            if (string.IsNullOrEmpty(User))
            {
                await dialogService.ShowMessage(Resource.TypeError, Resource.LoginIsEmailEntry, Resource.TypeValue);

                return;
            }
            if (!utilities.IsValidEmail(User))
            {
                await dialogService.ShowMessage(Resource.TypeError, Resource.LoginIsEmailValid, Resource.TypeValue);

                return;
            }
            if (!IsRemembermePassword)
            {
                if (string.IsNullOrEmpty(Password))
                {
                    await dialogService.ShowMessage(Resource.TypeError, Resource.LoginIsPasswordEntry, Resource.TypeValue);

                    return;
                }
            }
            var loginItemViewModel = new LoginItemViewModel
            {
                IsRemembermePassword      = IsRemembermePassword,
                IsAceptTermsAndConditions = IsAceptTermsAndConditions,
                IsNewUser = IsNewUser,
                Password  = Password,
                User      = User
            };
            var result = await apiService.Login(loginItemViewModel, "Login");

            if (result.IsSuccess && IsRemembered)
            {
                var user = new User()
                {
                    CreatedById  = User,
                    UpdatedById  = User,
                    Created      = DateTime.Now,
                    Address      = string.Empty,
                    FirstName    = string.Empty,
                    IsRemembered = IsRemembered,
                    LastName     = string.Empty,
                    Password     = Password,
                    Phone        = string.Empty,
                    Updated      = DateTime.Now,
                    UserName     = User
                };
                result = await dataService.InserUser(user, "Login");

                if (result.IsSuccess)
                {
                    var mainViewModel = MainViewModel.GetInstance();
                    mainViewModel.SetCurrentMenu(new MenuItemViewModel
                    {
                        Icon     = "ic_action_settings.png",
                        PageName = "logoutPage",
                        Title    = "Cerrar Session"
                    });
                    mainViewModel.IsRefreshingMenu = true;
                    await navigationService.Navigate("UsersPage");
                }
                // await dialogService.ShowMessage(Resource.TypeInformation, result.Message, Resource.TypeValue);
            }
        }