async void ChangePasswordClicked(object sender, EventArgs args) { ShowLoading(); var responseGPS = await InfoGPS.InformacionGPS(); if (!string.IsNullOrEmpty(responseGPS.Message)) { HideLoading(); ShowErrorMessage(responseGPS.Message); return; } ChangePasswordRequest changePasswordRequest = new ChangePasswordRequest { NickName = ChangePasswordViewModel.NickName, Code = Settings.Code, OldPassword = ChangePasswordViewModel.OldPassword, NewPassword = ChangePasswordViewModel.NewPassword, }; var jsonRequest = JsonConvert.SerializeObject(changePasswordRequest); var content = new StringContent(jsonRequest, Encoding.UTF8, "text/json"); var response = new Response(); string result; //envio try { response = await ApiService.ConsumoPOST(ApiService.URL, "api_appsiif/api/User/ChangePassword", content); result = response.Result; } catch { } if (response.Code >= 400) { ShowErrorMessage(response.Result); HideLoading(); return; } else if (response.Code >= 200 && response.Code < 300) { HideLoading(); ShowSuccessMessage("Cambio de ContraseƱa Exitoso"); Application.Current.MainPage = new LoginView(); } }
async void LoginClicked(object sender, EventArgs args) { ShowLoading(); var responseGPS = await InfoGPS.InformacionGPS(); if (!string.IsNullOrEmpty(responseGPS.Message)) { HideLoading(); ShowErrorMessage(responseGPS.Message); return; } LoginRequest loginRequest = new LoginRequest { NickName = LoginViewModel.TextNickName, Password = LoginViewModel.TextPassword, RegisterCode = Settings.RegisterCode, Longitude = responseGPS.Longitude, Latitude = responseGPS.Latitude, IpAdress = GetIpAdress(), TypeIncome = "1" }; var jsonRequest = JsonConvert.SerializeObject(loginRequest); var content = new StringContent(jsonRequest, Encoding.UTF8, "text/json"); var response = new Response(); string result; //envio try { response = await ApiService.ConsumoPOST(ApiService.URL, "api_appsiif/api/User/Login", content); result = response.Result; } catch (InvalidCastException e) { ShowErrorMessage(e.Message); HideLoading(); } if (response.Code >= 400) { ShowErrorMessage(response.Result); HideLoading(); return; } else if (response.Code >= 200 && response.Code < 300) { HideLoading(); ShowSuccessMessage("Bienvenido!"); } LoginResponse loginResponse = JsonConvert.DeserializeObject <LoginResponse>(response.Result); Settings.RefreshToken = loginResponse.RefreshToken; Settings.JwtToken = loginResponse.JwtToken; Settings.Code = loginResponse.Code; Settings.UserName = loginResponse.UserName; Application.Current.MainPage = new MenuView(loginResponse.UserName); }
async void RegisterClicked(object sender, EventArgs args) { ShowLoading(); var responseGPS = await InfoGPS.InformacionGPS(); if (!string.IsNullOrEmpty(responseGPS.Message)) { HideLoading(); ShowErrorMessage(responseGPS.Message); return; } RegisterRequest registerRequest = new RegisterRequest { NickName = RegisterViewModel.TextNickName, VerificationCode = RegisterViewModel.TextVerificationCode, DeviceName = CrossDeviceInfo.Current.DeviceName, DeviceSerial = CrossDeviceInfo.Current.Id, DeviceBrand = CrossDeviceInfo.Current.Manufacturer, DeviceModel = CrossDeviceInfo.Current.Model, DeviceOperatingSystem = CrossDeviceInfo.Current.Platform.ToString(), Longitude = responseGPS.Longitude, Latitude = responseGPS.Latitude, TypeIncome = "1" }; var jsonRequest = JsonConvert.SerializeObject(registerRequest); var content = new StringContent(jsonRequest, Encoding.UTF8, "text/json"); var response = new Response(); string result; //envio try { response = await ApiService.ConsumoPOST(ApiService.URL, "api_appsiif/api/User/Register", content); result = response.Result; } catch (InvalidCastException e) { ShowErrorMessage(e.Message); HideLoading(); } if (response.Code >= 400) { ShowErrorMessage(response.Result); HideLoading(); return; } else if (response.Code >= 200 && response.Code < 300) { RegisterResponse registerResponse = JsonConvert.DeserializeObject <RegisterResponse>(response.Result); Settings.RegisterCode = registerResponse.RegisterCode; HideLoading(); ShowSuccessMessage("Registro de dispositivo exitoso."); Application.Current.MainPage = new ChangePasswordView(RegisterViewModel.TextVerificationCode); } }