Esempio n. 1
0
 public MainPage()
 {
     InitializeComponent();
     NavigationPage.SetHasNavigationBar(this, false);
     _apiServices            = new RestApi();
     _baseUrl                = Settings.Url + Domain.LoginApiConstant;
     _objOTPResponseModel    = new OTPResponseModel();
     _objOTPRequestModel     = new OTPRequestModel();
     entryPhoneNo.Completed += (sender, e) =>
     {
         btnphoneNoSubmit_Clicked(sender, e);
     };
 }
Esempio n. 2
0
        private async void btnphoneNoSubmit_Clicked(object sender, EventArgs e)
        {
            try
            {
                var txtEntry = entryPhoneNo.Text;
                _objOTPRequestModel.PhoneNo    = txtEntry;
                _objOTPRequestModel.DeviceId   = "1";
                _objOTPRequestModel.DeviceType = "Android";
                if (string.IsNullOrEmpty(txtEntry) || txtEntry.Length < 10 || txtEntry.Length > 15)
                {
                    DependencyService.Get <IToast>().ShowToast("Your Phone Number should be of 10 digits!!");
                }
                else
                {
                    await Navigation.PushPopupAsync(new LoadingPopPage());

                    _objOTPResponseModel = await _apiServices.LoginAsync(new Get_API_Url().LoginApi(_baseUrl), false, new HeaderModel(), _objOTPRequestModel);

                    var Result = _objOTPResponseModel.Response;
                    if (Result.StatusCode == 200)
                    {
                        Settings.PhoneNo = txtEntry;
                        // DependencyService.Get<IToast>().ShowToast(Result.Message);
                        await App.NavigationPage.Navigation.PushAsync(new OTPVerificationPage(Result));

                        await Navigation.PopAllPopupAsync();
                    }
                    else
                    {
                        DependencyService.Get <IToast>().ShowToast(Result.Message);
                        await Navigation.PopAllPopupAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                DependencyService.Get <IToast>().ShowToast("Something Went Wrong please try Again or check your Internet Connection!!");
                await Navigation.PopAllPopupAsync();

                var msg = ex.Message;
            }
        }
Esempio n. 3
0
        //POST APIS..........................
        public async Task <OTPResponseModel> LoginAsync(string uri, Boolean IsHeaderRequired, HeaderModel objHeaderModel, OTPRequestModel _objOTPRequestModel)
        {
            client.MaxResponseContentBufferSize = 256000;
            OTPResponseModel _objOTPResponseModel = new OTPResponseModel();

            var keyValues = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("PhoneNo", _objOTPRequestModel.PhoneNo),
                new KeyValuePair <string, string>("DeviceId", _objOTPRequestModel.DeviceId),
                new KeyValuePair <string, string>("DeviceType", _objOTPRequestModel.DeviceType)
            };

            if (IsHeaderRequired)
            {
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Length", "69");
                client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Fiddler");
                client.DefaultRequestHeaders.TryAddWithoutValidation("Host", "localhost:49165");
            }
            var request = new HttpRequestMessage(HttpMethod.Post, uri);

            request.Content = new FormUrlEncodedContent(keyValues);

            HttpResponseMessage response = await client.SendAsync(request);

            var statuscode = Convert.ToInt64(response.StatusCode);

            if (response.IsSuccessStatusCode)
            {
                var SucessResponse = await response.Content.ReadAsStringAsync();

                _objOTPResponseModel = JsonConvert.DeserializeObject <OTPResponseModel>(SucessResponse);
                return(_objOTPResponseModel);
            }
            else
            {
                var ErrorResponse = await response.Content.ReadAsStringAsync();

                _objOTPResponseModel = JsonConvert.DeserializeObject <OTPResponseModel>(ErrorResponse);
                return(_objOTPResponseModel);
            }
        }