async void acceptRide(Models.ActiveRequest request, string destAddr) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0"); request.EndTime = System.DateTime.Now; //Delete old request var response_post = await client.DeleteAsync("http://thehopper.azurewebsites.net/api/ActiveRequests/" + request.ID); var responseString_post = await response_post.Content.ReadAsStringAsync(); Debug.WriteLine("Old request deleted"); Debug.WriteLine(responseString_post); //Create new request with valid EndTime string ser_obj = JsonConvert.SerializeObject(request); var content_post = new StringContent(ser_obj, Encoding.UTF8, "text/json"); //post it to the proper table response_post = await client.PostAsync("http://thehopper.azurewebsites.net/api/ActiveRequests/", content_post); responseString_post = await response_post.Content.ReadAsStringAsync(); Debug.WriteLine("New request created with EndTime"); Debug.WriteLine(responseString_post); } await DisplayAlert("Ride Accepted", "Destination: " + destAddr, "Back"); refreshData(this, null); }
async void onPinClick(Object sender, SelectedPinChangedEventArgs e) { if (e.SelectedPin != null) { int selectedID = Int32.Parse(e.SelectedPin.Label); Models.ActiveRequest request = null; foreach (var req in requests) { if (req.ID == selectedID) { request = req; } } Debug.WriteLine("Ride ID = " + request.ID); string startAddr = await getAddress(request.StartLocation); string destAddr = await getAddress(request.EndLocation); //Display info about request and option to accept ride var accept = await DisplayAlert("Accept this ride?", "Location: " + startAddr + "\n\nDestination: " + destAddr + "\n\nRequest time: " + request.StartTime.ToString() + "\n\nNumber of Passengers: " + request.NumPassangers, "Yes", "No"); if (accept) { acceptRide(request, destAddr); } } }
/* * void onDropClicked(object sender, EventArgs e) * { * Pin destination = new Pin(); * * destination.Position = new Position(43.068152, -89.409759); * destination.Label = "Hold to Drag"; * * map.Pins.Add(destination); * * * } */ async void onSubmitClicked(Object sender, EventArgs e) { //Add code to submit ride request to database if (App.riderID == 0) { await DisplayAlert("Bad Login", "Rider ID is invalid, please log in via Facebook", "Back To Main Menu"); await Navigation.PushModalAsync(new MyPage()); } else if (map.Pins.Count() != 2) { await DisplayAlert("Missing Starting Point or Destination", "Please make sure you have a valid starting point and destination", "OK"); } else { List <Models.ActiveRequest> reqList = new List <Models.ActiveRequest>(); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0"); Debug.WriteLine("Before the request to server"); var reqResponse = await client.GetAsync("http://thehopper.azurewebsites.net/api/ActiveRequests/"); //This will be an IQueryable object Debug.WriteLine("Before the response from server"); string reqResponseStr = await reqResponse.Content.ReadAsStringAsync(); Debug.WriteLine("After the response from server"); //The following will convert the json to an actual rider object reqList = JsonConvert.DeserializeObject <List <Models.ActiveRequest> >(reqResponseStr); } App.activeReqID = reqList[reqList.Count - 1].ID + 1; Models.ActiveRequest req = new Models.ActiveRequest(); req.ID = App.activeReqID; req.RiderID = App.riderID; if (map.Pins[0].Label == "Starting Point") { req.StartLocation = map.Pins[0].Position.Latitude + "," + map.Pins[0].Position.Longitude; req.EndLocation = map.Pins[1].Position.Latitude + "," + map.Pins[1].Position.Longitude;; } else { req.StartLocation = map.Pins[1].Position.Latitude + "," + map.Pins[1].Position.Longitude; req.EndLocation = map.Pins[0].Position.Latitude + "," + map.Pins[0].Position.Longitude; } var subPage = new SubmissionPage(req, start.Text, dest.Text); subPage.ButtonClicked += OnFinalSubmission; await Navigation.PushModalAsync(subPage); } }
public SubmissionPage(Models.ActiveRequest req, string startAddr, string destAddr) { InitializeComponent(); passengerCount.Items.Add("1"); passengerCount.Items.Add("2"); passengerCount.Items.Add("3"); passengerCount.Items.Add("4"); passengerCount.Items.Add("5"); passengerCount.Items.Add("6"); start.Text += startAddr; dest.Text += destAddr; request = req; }