/// <summary>
        /// Gets a restaurant by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Restaurant GetRestaurantById(string id)
        {
            Restaurant returned = new Restaurant();
            if (!String.IsNullOrEmpty(id))
            {
                using (HttpWebResponse response = TP01RestApiWebCall.CallGetRestaurantByIdSynchronous(id))
                {
                    // Get the stream associated with the response.
                    Stream receiveStream = response.GetResponseStream();

                    // Pipes the stream to a higher level stream reader with the required encoding format.
                    using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
                    {
                        returned = JsonConvert.DeserializeObject<Restaurant>(readStream.ReadToEnd());
                    }
                }
            }
            return returned;
        }
Exemple #2
0
        /// <summary>
        /// Modifier
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(_currentModifRestaurantId))
            {
                Restaurant resto = new Restaurant(Convert.ToInt32(ComboBoxListeRestoModif.Text), ModifComboBoxPrix.Text, ModifTextBoxNom.Text, ModifTextBoxDescription.Text, ModifTextBoxCategoriePrix.Text, ModifTextBoxAdresse1.Text, ModifTextBoxAdresse2.Text, ModifTextBoxAdresse3.Text, ModifTextBoxAdresse4.Text, Convert.ToInt32(ModifTextBoxTel1.Text), ModifTextBoxTel2.Text, ModifTextBoxWeb.Text, ModifTextBoxMail.Text);
                string restoJson = JsonConvert.SerializeObject(resto);

                if (Settings.Default.AsyncMode)
                {
                    TP01RestApiWebCall.CallPutRestaurantAsynchronous(_currentModifRestaurantId, restoJson, new AsyncCallback(this.Button_Click_6_CallBack));
                }
                else
                {
                    using (HttpWebResponse response = TP01RestApiWebCall.CallPutRestaurantSynchronous(_currentModifRestaurantId, restoJson))
                    {
                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            ModifButton.IsEnabled = false;
                            ComboBoxListeRestoModif.Text = String.Empty;
                            ModifComboBoxPrix.Text = String.Empty;
                            ModifTextBoxNom.Text = String.Empty;
                            ModifTextBoxDescription.Text = String.Empty;
                            ModifTextBoxCategoriePrix.Text = String.Empty;
                            ModifTextBoxAdresse1.Text = String.Empty;
                            ModifTextBoxAdresse2.Text = String.Empty;
                            ModifTextBoxAdresse3.Text = String.Empty;
                            ModifTextBoxAdresse4.Text = String.Empty;
                            ModifTextBoxTel1.Text = String.Empty;
                            ModifTextBoxTel2.Text = String.Empty;
                            ModifTextBoxWeb.Text = String.Empty;
                            ModifTextBoxMail.Text = String.Empty;
                        }
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Rechercher avant modif callback
 /// </summary>
 /// <param name="result"></param>
 private void Button_Click_5_CallBack(IAsyncResult result)
 {
     using (HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse)
     {
         Restaurant resto = new Restaurant();
         Stream receiveStream = response.GetResponseStream();
         using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
         {
              resto = JsonConvert.DeserializeObject<Restaurant>(readStream.ReadToEnd());
         }
         ModifTextBoxAdresse1.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxAdresse1.Text = resto.res_adr; }));
         ModifTextBoxAdresse2.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxAdresse2.Text = resto.RES_CP; }));
         ModifTextBoxAdresse3.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxAdresse3.Text = resto.RES_VILLE; }));
         ModifTextBoxAdresse4.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxAdresse4.Text = resto.RES_PAYS; }));
         ModifTextBoxCategoriePrix.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxCategoriePrix.Text = resto.RES_CATEGORIEPRIX; }));
         ModifTextBoxDescription.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxDescription.Text = resto.RES_DESCRIPTION; }));
         ModifTextBoxMail.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxMail.Text = resto.RES_MEL; }));
         ModifTextBoxNom.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxNom.Text = resto.RES_NOM; }));
         ModifComboBoxPrix.Dispatcher.BeginInvoke(new Action(() => { ModifComboBoxPrix.Text = resto.PRX_PRIX; }));
         ModifTextBoxTel1.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxTel1.Text = resto.IND_INDICATIF.ToString(); ; }));
         ModifTextBoxTel2.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxTel2.Text = resto.RES_TEL; }));
         ModifTextBoxWeb.Dispatcher.BeginInvoke(new Action(() => { ModifTextBoxWeb.Text = resto.RES_SITEWEB; }));
     }
 }
Exemple #4
0
        /// <summary>
        /// Create
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            Restaurant resto = new Restaurant(AddComboBoxPrix.Text, AddTextBoxNom.Text, AddTextBoxDescription.Text, AddTextBoxCategoriePrix.Text, AddTextBoxAdresse1.Text, AddTextBoxAdresse2.Text, AddTextBoxAdresse3.Text, AddTextBoxAdresse4.Text, Convert.ToInt32(AddTextBoxTel1.Text), AddTextBoxTel2.Text, AddTextBoxWeb.Text, AddTextBoxMail.Text);
                string restoJson = JsonConvert.SerializeObject(resto);
            if (Settings.Default.AsyncMode)
            {
                TP01RestApiWebCall.CallPostRestaurantAsynchronous(restoJson, new AsyncCallback(this.Button_Click_4_CallBack));
            }
            else
            {

                using (HttpWebResponse response = TP01RestApiWebCall.CallPostRestaurantSynchronous(restoJson))
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.Created)
                    {
                        AddComboBoxPrix.Text = String.Empty;
                        AddTextBoxNom.Text = String.Empty;
                        AddTextBoxDescription.Text = String.Empty;
                        AddTextBoxCategoriePrix.Text = String.Empty;
                        AddTextBoxAdresse1.Text = String.Empty;
                        AddTextBoxAdresse2.Text = String.Empty;
                        AddTextBoxAdresse3.Text = String.Empty;
                        AddTextBoxAdresse4.Text = String.Empty;
                        AddTextBoxTel1.Text = String.Empty;
                        AddTextBoxTel2.Text = String.Empty;
                        AddTextBoxWeb.Text = String.Empty;
                        AddTextBoxMail.Text = String.Empty;
                    }
                }
            }
        }