Esempio n. 1
0
        private async void Register()
        {
            //  Validate the field of form
            var response = MethodsHelper.IsValidField(
                "S",
                3,
                20,
                "firts name",
                this.FirtsName,
                true,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                3,
                20,
                "last name",
                this.LastName,
                true,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.Email,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.Email);

            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid email",
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                6,
                10,
                "password",
                this.Password,
                true,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                6,
                10,
                "password confirm",
                this.Confirm,
                true,
                true,
                this.Password);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(false, true, true, 1);

            response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Use the user registration API
            var user = new User
            {
                AppName    = MethodsHelper.GetAppName(),
                Email      = this.Email,
                FirstName  = this.FirtsName,
                LastName   = this.LastName,
                Password   = this.Password,
                UserTypeId = Convert.ToInt32("5"),
            };

            response = await apiService.Post(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users",
                user);

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(true, true, false, 0);

            //  Set Initialize the fields
            SetInitializaFields();

            //  Go back login
            await dialogService.ShowMessage(
                "Information",
                string.Format(
                    "{0}{1}",
                    "User registered successfully, you can now log in to the ",
                    "application whit this username and password...!!!"),
                "Accept");

            await navigationService.GoBackOnLogin();
        }
        private async void Recovery()
        {
            var response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.Email,
                false,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.Email);

            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid email...!!!",
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(false, true, "Green", 1);

            response = await apiService.PasswordRecovery(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users/PasswordRecovery",
                this.Email);

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, false, "Green", 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(true, false, "Green", 0);

            //  Set Initialize the fields
            LoadValuesControls(0);

            //  Go back login
            await dialogService.ShowMessage(
                "Information",
                "You new password has been successfully sent to email...!!!",
                "Accept");

            //  Navigate to LoginPage
            await navigationService.GoBackOnLogin();
        }
Esempio n. 3
0
        private async void Save()
        {
            //  Validate the field of form
            #region Current Email

            var response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.CurrentEmail,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.CurrentEmail);
            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid current email",
                    "Accept");

                return;
            }

            #endregion Current Email

            // Verify if it is valid the email current
            if (!this.CurrentEmail.Equals(this.mainViewModel.UserData.Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "This email not are registered in the sistem...!!!",
                    "Accept");

                return;
            }

            #region New Email

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "new email",
                this.NewEmail,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            isValidEmail = MethodsHelper.IsValidEmail(this.NewEmail);
            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid new email",
                    "Accept");

                return;
            }

            #endregion New Email

            #region Confirm Email

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "confirm email",
                this.ConfirmEmail,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            isValidEmail = MethodsHelper.IsValidEmail(this.ConfirmEmail);
            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid confirm email",
                    "Accept");

                return;
            }

            #endregion Confirm Email

            #region Email Confirm and new Email

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email confirm",
                this.ConfirmEmail,
                false,
                true,
                this.NewEmail);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            #endregion Email Confirm and new Email

            //  Validate that the emails are different
            if (this.CurrentEmail.Equals(this.NewEmail))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The new email can not be the same as the current email .. !!!",
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(false, true, "Green", 1);

            response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, false, "Green", 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Use the user registration API
            var userEdit = new UserEdit
            {
                AppName    = MethodsHelper.GetAppName(),
                Email      = this.mainViewModel.UserData.Email,
                FirstName  = this.mainViewModel.UserData.FirstName,
                LastName   = this.mainViewModel.UserData.LastName,
                NewEmail   = this.newEmail,
                Password   = this.mainViewModel.UserData.Password,
                UserId     = this.mainViewModel.UserData.UserId,
                UserTypeId = 5,
            };

            response = await apiService.Put <UserEdit>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users/PutUserEdit",
                "id",
                this.mainViewModel.Token.TokenType,
                this.mainViewModel.Token.AccessToken,
                userEdit);

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, false, "Green", 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(true, false, "Green", 0);

            //  Set Initialize the fields
            LoadValuesControls(0);

            //  Go back login
            await dialogService.ShowMessage(
                "Information",
                "Successfully modified email, you must log in again...!!! ",
                "Accept");

            //  Navigate to LoginPage
            navigationService.SetMainPage("LoginPage");
        }
        private async void Login()
        {
            //  Validate the fields of form
            var response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.Email,
                false,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.Email);

            if (!isValidEmail)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid email",
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "password",
                this.Password,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Establece el estatus de los controles
            this.SetStatusControl(false, true, true, 1);

            //  Validate if there is an internet connection
            response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Establece el estatus de los controles
                this.SetStatusControl(true, true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Get user Token
            var token = await this.apiService.GetToken(
                Email,
                Password,
                MethodsHelper.GetUrlAPI());

            if (token != null)
            {
                if (!string.IsNullOrEmpty(token.ErrorDescription))
                {
                    //  EStablishes the status of controls
                    this.SetStatusControl(true, true, false, 0);

                    await this.dialogService.ShowMessage(
                        "Error",
                        token.ErrorDescription,
                        "Accept");

                    return;
                }
            }
            else
            {
                //  Establishes the status of controls
                this.SetStatusControl(true, true, false, 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    "An error has occurred, try later...!!!",
                    "Accept");

                return;
            }

            //  Get new instance of ViewModel (Token)
            this.mainViewModel.Token = token;

            //  Get new instance of MenuViewModel
            //  MainViewModel.GetInstance().Menu = new MenuViewModel();

            //  Establishes the status of controls
            this.SetInitialize();
            this.SetStatusControl(true, true, false, 0);

            //  Navigate to the page
            //  await navigationService.NavigateOnMaster("MenuPage");

            //  MainViewModel.GetInstance().Cantv = new CantvViewModel();
            this.mainViewModel.Cantv = new CantvViewModel();

            //  Define the MainPage
            this.navigationService.SetMainPage("MasterPage");
        }