예제 #1
0
        public async Task <bool> UpdateRequestCar(string Id, VeLogCars velogCar)
        {
            try
            {
                Uri    requestUri = new Uri("http://velogdataentry.azurewebsites.net/api/VelogCarsAPI/" + Id);
                string json       = "";
                json = Newtonsoft.Json.JsonConvert.SerializeObject(velogCar);
                var objClient = new HttpClient();
                HttpResponseMessage responseUpdate = await objClient.PutAsync(requestUri, new StringContent(json, System.Text.Encoding.UTF8, "application/json"));

                if (responseUpdate.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception exCarUpdate)
            {
                var messageDialog = new MessageDialog("Error: " + exCarUpdate);
                await messageDialog.ShowAsync();

                return(false);
            }
        }
예제 #2
0
        // ****************************************************************************************************
        // displaying a seleced data grid item in text boxes

        private void cars_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            if (dataGridCars.SelectedIndex > -1)
            {
                VeLogCars recordCar = (VeLogCars)dataGridCars.SelectedItem; //casting the object

                txtCarId.Text     = recordCar.Id.ToString();
                txtCarRego.Text   = recordCar.Registration;
                txtCarMake.Text   = recordCar.Make;
                txtCarModel.Text  = recordCar.Model;
                txtCarColour.Text = recordCar.Colour;
            }
        }
예제 #3
0
        private async void btnUpdateCar_Click(object sender, RoutedEventArgs e)
        {
            if (dataGridCars.SelectedIndex > -1)
            {
                if (txtCarRego.Text != "" && txtCarMake.Text != "" && txtCarModel.Text != "" && txtCarColour.Text != "")
                {
                    if (txtCarRego.Text.Length <= 100 && txtCarMake.Text.Length <= 100 && txtCarModel.Text.Length <= 100 && txtCarColour.Text.Length <= 100)
                    {
                        VeLogCars velogCar = new VeLogCars();
                        velogCar.Id           = Convert.ToInt32(txtCarId.Text);
                        velogCar.Registration = txtCarRego.Text;
                        velogCar.Make         = txtCarMake.Text;
                        velogCar.Model        = txtCarModel.Text;
                        velogCar.Colour       = txtCarColour.Text;

                        objRest = new RESTHandler();
                        bool status = await objRest.UpdateRequestCar(txtCarId.Text, velogCar);

                        if (status == true)
                        {
                            LoadCarData();
                        }
                        else
                        {
                            var messageDialog = new MessageDialog("An error occurred, Car not updated.");
                            await messageDialog.ShowAsync();
                        }

                        ClearCarTextFields();
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Check length of Car details.");
                        await messageDialog.ShowAsync();
                    }
                }
                else
                {
                    var messageDialog = new MessageDialog("Enter Car details.");
                    await messageDialog.ShowAsync();
                }
            }
            else
            {
                var messageDialog = new MessageDialog("No record selected.");
                await messageDialog.ShowAsync();
            }
        }