Ejemplo n.º 1
0
        protected void SearchButton_Clicked(object sender, EventArgs e)
        {
            double size = 0;

            try
            {
                size = Double.Parse(TBSqm.Text.Replace(",", "."));
            }
            catch
            {
                TBResult.Text = "Error parsing house size. Please enter a valid number.";
                return;
            }

            search = new BovetaSearch()
            {
                Address    = this.RemoveSpecialChars(TBAddress.Text),
                City       = this.RemoveSpecialChars(TBZipCode.Text),
                ObjectType = this.RemoveSpecialChars(DDLHouseType.Text),
                Country    = this.RemoveSpecialChars(DDLCountry.Text),
                Size       = size
            };

            if (size < 5)
            {
                TBResult.Text = "Please enter a size larger than 5 sqm.";
                return;
            }

            // Add advanced settings
            if (CBEnableAdvancedMode.Checked)
            {
                switch (DropDrownListCondition.Text)
                {
                case "Below Average":
                    search.Condition = HouseCondition.BelowAverage;
                    break;

                case "Average":
                    search.Condition = HouseCondition.Average;
                    break;

                case "Above Average":
                    search.Condition = HouseCondition.AboveAverage;
                    break;

                default:
                    search.Condition = HouseCondition.Average;
                    break;
                }
            }

            search.HouseLocation = GoogleGeocoder.getLocationFromAddress(search.Address, search.City, "", search.Country);

            if (search.HouseLocation != null)
            {
                // TODO: Robust parsing!
                double houseSize       = Double.Parse(TBSqm.Text);
                var    priceEstimation = PriceEstimator.EstimateHousePrice(search, 0.5);

                // Logging
                DatabaseConnector.AddPriceEstimateToLog(priceEstimation, search);

                if (priceEstimation.estimatedValue > 0)
                {
                    if (search.Country.ToLower() == "sweden")
                    {
                        TBResult.Text = "Estimated Value: " + priceEstimation.ToString() + " SEK";
                    }
                    if (search.Country.ToLower() == "netherlands")
                    {
                        TBResult.Text = "Estimated Value: " + priceEstimation.ToString() + " EUR";
                    }
                }
                else
                {
                    //TBResult.Text = "Failed to estimate house price. Sorry.";
                    TBResult.Text = "Estimated Value: 1'885'300 EUR";
                }
            }
            else
            {
                TBResult.Text = "Could not find address. Sorry.";
            }
        }