Пример #1
0
        async void Save()
        {
            if (string.IsNullOrEmpty(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a email.");

                return;
            }

            if (!RegexUtilities.IsValidEmail(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a valid email.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var apiSecurity = Application.Current.Resources["ApiProduct"].ToString();

            var response = await apiService.PasswordRecovery(
                apiSecurity,
                "/api",
                "/Customers/PasswordRecovery",
                Email);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    "We can't send the new password to this email.");

                return;
            }

            await dialogService.ShowMessage(
                "Confirm",
                "Your new password has been sent to your email!");

            await navigationService.BackOnLogin();

            IsRunning = false;
            IsEnabled = true;
        }
Пример #2
0
        async void Save()
        {
            if (string.IsNullOrEmpty(FirstName))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a first name.");

                return;
            }

            if (string.IsNullOrEmpty(LastName))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a last name.");

                return;
            }

            if (string.IsNullOrEmpty(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a email.");

                return;
            }

            if (!RegexUtilities.IsValidEmail(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a valid email.");

                return;
            }

            if (string.IsNullOrEmpty(Password))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a password.");

                return;
            }

            if (Password.Length < 6)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The password must have at least 6 characters length.");

                return;
            }

            if (string.IsNullOrEmpty(Confirm))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a password confirm.");

                return;
            }

            if (!Password.Equals(Confirm))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The password and confirm, does not match.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var customer = new Customer
            {
                Address      = Address,
                CustomerType = 1,
                Email        = Email,
                FirstName    = FirstName,
                LastName     = LastName,
                Password     = Password,
                Phone        = Phone,
            };

            var apiServiceWithoutConnection = (ApiServiceWithoutConnection)apiService;
            var response = await apiServiceWithoutConnection.PostCustomers(
                "http://productszuluapi.azurewebsites.net",
                "/api",
                "/Customers",
                customer);



            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            var response2 = await apiService.GetToken(
                "http://productszuluapi.azurewebsites.net",
                Email,
                Password);

            if (response2 == null)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    "The service is not available, please try latter.");

                Password = null;
                return;
            }

            if (string.IsNullOrEmpty(response2.AccessToken))
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response2.ErrorDescription);

                Password = null;
                return;
            }

            var mainViewModel = MainViewModel.GetInstance();

            mainViewModel.Token = response2;
            mainViewModel.CategoriesViewModel = new CategoriesViewModel();
            await navigationService.BackOnLogin();

            navigationService.SetMainPage("MasterView");

            IsRunning = false;
            IsEnabled = true;
        }
 async void Cancel()
 {
     await navigationService.BackOnLogin();
 }