Exemple #1
0
 private void ShowRealEstate(RealEstate realestate)
 {
     lblGardenSquaremetersDetail.Content = realestate.getGarden_squaremeter() + " m2";
     lblLocationDetail.Content           = realestate.getLocation();
     lblParkinglotsDetail.Content        = realestate.getNum_of_parkinglots();
     lblPriceDetail.Content        = realestate.getPrice() + " €";
     lblRoomsDetail.Content        = realestate.getRooms();
     lblSquaremetersDetail.Content = realestate.getSquaremeter() + " m2";
     lblTypeDetail.Content         = realestate.GetType();
 }
        private async void BtnCreate_Click(object sender, RoutedEventArgs e)
        {
            RealEstate realEstate = RealEstateFactory.addRealEstate(
                (Location)Enum.Parse(typeof(Location), cbxLocation.SelectedItem.ToString()),
                (RealEstateType)Enum.Parse(typeof(RealEstateType), cbxTypes.SelectedItem.ToString()),
                Convert.ToDouble(txtSquaremeter.Text, CultureInfo.InvariantCulture),
                Convert.ToInt32(txtRooms.Text),
                Convert.ToDouble(txtGardenSquaremeter.Text, CultureInfo.InvariantCulture),
                Convert.ToInt32(txtParkinglots.Text));

            if (realEstate != null)
            {
                txtResult.Text = "Result: \n" + realEstate.ToString();
                string stringPayload = await Task.Run(() => JsonConvert.SerializeObject(new RealEstateModel(realEstate.GetType().Name, realEstate.getLocation().ToString(), realEstate.getRooms(), realEstate.getSquaremeter(), realEstate.getGarden_squaremeter(), realEstate.getNum_of_parkinglots())));

                StringContent       httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
                HttpResponseMessage response    = await DAL.PostAsync(REST_URL, httpContent);

                if (response.IsSuccessStatusCode)
                {
                    btnShowInList.IsEnabled = true;
                }
                else
                {
                    btnShowInList.IsEnabled = false;
                }
            }
            else
            {
                txtResult.Text = "Not possible to create " + cbxTypes.SelectedItem.ToString() + " in " + cbxLocation.SelectedItem.ToString() + ".";
            }
        }