public async void OnUpdateWardenInfoCommand() { string emailpattern = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; Regex emailRegx = new Regex(emailpattern); if (string.IsNullOrEmpty(Name) || Name.Length == 0) { await App.Current.MainPage.DisplayAlert("HMS", "Enter Name", "OK"); } else if (string.IsNullOrEmpty(Mobileno) || Mobileno.Length == 0) { await App.Current.MainPage.DisplayAlert("HMS", "Enter phone no", "OK"); } else if (Mobileno.Length != 10) { await App.Current.MainPage.DisplayAlert("HMS", "Please Enter 10 digit mobile no.", "OK"); } else if (string.IsNullOrEmpty(Aadharno) || Aadharno.Length == 0) { await App.Current.MainPage.DisplayAlert("HMS", "Enter AAdhar no.", "OK"); } else if (Aadharno.Length != 9) { await App.Current.MainPage.DisplayAlert("HMS", "Please Enter 9 digit Aadhar no.", "OK"); } else if (string.IsNullOrEmpty(Email) || Email.Length == 0) { await App.Current.MainPage.DisplayAlert("HMS", "Enter email.", "OK"); } else if (string.IsNullOrEmpty(Fulladdress) || Fulladdress.Length == 0) { await App.Current.MainPage.DisplayAlert("HMS", "Enter Address.", "OK"); } else if (emailRegx.IsMatch(Email) == false) { await App.Current.MainPage.DisplayAlert("HMS", "Enter Valid Email Address", "OK"); } else if (string.IsNullOrEmpty(Newpassword) || Newpassword.Length == 0) { await App.Current.MainPage.DisplayAlert("HMS", "Enter New Password", "Ok"); } else if (Newpassword == CnfPassword) { WardenRegistration warden = new WardenRegistration(); warden.wardenName = Name; warden.address = Fulladdress; warden.phoneNo = Mobileno; warden.email = Email; warden.wardenEmail = Email; warden.userName = Username; warden.password = Newpassword; warden.adharNo = Aadharno; warden.gender = Gender; wardenservice.SavewardenData(warden); } else { await App.Current.MainPage.DisplayAlert("", "Password Doesn't match", "OK"); } }
public async void SavewardenData(WardenRegistration wardenRegistration) { string resultHostel; WardenResponse wardenResponse; Wardenerrorresponse wardenerrorresponse; try { UserDialogs.Instance.ShowLoading(); var client = new HttpClient(); client.BaseAddress = new Uri(ApplicationURL.BaseURL); string json = JsonConvert.SerializeObject(wardenRegistration); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(ApplicationURL.WardenRegistration, content); resultHostel = await response.Content.ReadAsStringAsync(); if ((int)response.StatusCode == 200) { UserDialogs.Instance.HideLoading(); resultHostel = await response.Content.ReadAsStringAsync(); wardenResponse = JsonConvert.DeserializeObject <WardenResponse>(resultHostel); wardenregistration.wardenregistrationresponse(wardenResponse.message); } else { UserDialogs.Instance.HideLoading(); resultHostel = await response.Content.ReadAsStringAsync(); wardenerrorresponse = JsonConvert.DeserializeObject <Wardenerrorresponse>(resultHostel); wardenregistration.wardenregistrationresponse(wardenerrorresponse.errors[0].message); } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); await App.Current.MainPage.DisplayAlert("", ex.ToString(), "OK"); } }