private async void GenerateButton_Clicked_1(object sender, EventArgs e)
        {
            if (SurveyPicker.SelectedIndex != -1)
            {
                ISurveyPinHandler _SurveyPin = new SurveyPinHandler();
                bool   PinExists             = true;
                string NewSurveyPin          = "";
                PinPickerLayout.IsVisible      = false;
                PinActivityIndicator.IsVisible = true;
                while (PinExists)
                {
                    string Response = "";
                    NewSurveyPin = Guid.NewGuid().ToString().Substring(0, 5);
                    string SurveyPinResponse = await Task.Run(() => Response = _SurveyPin.GetSurveyPin(new cSurveysPin {
                        PinNumber = NewSurveyPin, SurveyId = (SurveyPicker.SelectedItem as cSurvey).SurveyId, PinGeneratedDatetime = DateTime.Now, PinUsedDateTime = DateTime.Now
                    }));

                    cSurveysPin _Pin = JsonConvert.DeserializeObject <cSurveysPin>(Response.ToString());
                    if (_Pin.SurveyId == 0)
                    {
                        PinExists = false;
                    }
                }
                string PinResponse = "";
                await Task.Run(() => PinResponse = _SurveyPin.InsertPin(new cSurveysPin {
                    PinNumber = NewSurveyPin, PinGeneratedDatetime = DateTime.Now, SurveyId = (SurveyPicker.SelectedItem as cSurvey).SurveyId
                }));

                PinPickerLayout.IsVisible      = true;
                PinActivityIndicator.IsVisible = false;
                if (PinResponse == "false")
                {
                    PinLabel.Text = PinResponse = "Sorry ,Pin cannot be generated at this time.";
                }
                else
                {
                    PinLabel.Text = NewSurveyPin;
                }
                PinLabel.IsVisible = true;
            }
            else
            {
                await DisplayAlert("Message", "Please select a survey first.", "OK");
            }
        }
Exemple #2
0
 public string UpdatePinUsedGeneratedDateTime(cSurveysPin Pin)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
        public string InsertPin(cSurveysPin Pin)
        {
            string mStatusResponse = "";

            if (Reachability.IsHostReachable("http://www.google.co.uk"))
            {
                try
                {
                    var mRequest = HttpWebRequest.Create(""); // removed for security.
                    mRequest.ContentType        = "application/json";
                    mRequest.Method             = "POST";
                    mRequest.Headers["KeyCode"] = ""; // removed for security.

                    JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
                    {
                        DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
                    };
                    var mJSON = JsonConvert.SerializeObject(Pin, microsoftDateFormatSettings);
                    using (StreamWriter sw = new StreamWriter(mRequest.GetRequestStream()))
                    {
                        sw.Write(mJSON);
                        sw.Flush();
                        sw.Close();
                    }
                    using (HttpWebResponse mResponse = mRequest.GetResponse() as HttpWebResponse)
                    {
                        mStatusResponse = ((HttpWebResponse)mResponse).StatusDescription;
                        if (mResponse.StatusCode != HttpStatusCode.OK)
                        {
                            return("Error");
                        }
                        else
                        {
                            using (StreamReader sr = new StreamReader(mResponse.GetResponseStream()))
                            {
                                var content = sr.ReadToEnd();
                                if (string.IsNullOrWhiteSpace(content))
                                {
                                    return("No Content");
                                }
                                else
                                {
                                    string SurveyPin;
                                    SurveyPin = JsonConvert.DeserializeObject <string>(content);
                                    return(SurveyPin);
                                }
                            }
                        }
                    }
                }
                catch (WebException ex)
                {
                    string mStatus = (ex.Response as HttpWebResponse)?.StatusCode.ToString();
                    return(mStatus);
                }
            }
            else
            {
                return("No internet connectiuon");
            }
        }
Exemple #4
0
 public string DeleteSurveyPin(cSurveysPin Pin)
 {
     throw new NotImplementedException();
 }