public OfferedRentOutput processOfferedRentInput(OfferedRentInput offeredRentInput, string userAgent) { OfferedRentOutput offeredRentOutput = new OfferedRentOutput(); CalculateRent(offeredRentInput, offeredRentOutput); offeredRentOutput.qualityMicro = offeredRentInput.qualityMicro ?? 0; offeredRentOutput.zip = offeredRentInput.address.zip; offeredRentOutput.town = offeredRentInput.address.town; offeredRentOutput.street = offeredRentInput.address.street; offeredRentOutput.CategoryCode = offeredRentInput.categoryCode; offeredRentOutput.country = offeredRentInput.address.country; ////Saving try { SaveRentPropertyDetails(MapRentBuisnessDataToDatabaseModel(null, null, null, offeredRentInput.deviceId, offeredRentOutput), userAgent); } catch (Exception ex) { RealEstateRepository realEstateRepository = new RealEstateRepository(); realEstateRepository.saveException(ex.Message, Convert.ToString(ex.InnerException), ex.StackTrace); return(offeredRentOutput); } return(offeredRentOutput); }
private void CalculateRent(OfferedRentInput offeredRentInput, OfferedRentOutput offeredRentOutput) { string priceUrl = String.Format("{0}/{1}", ConfigurationManager.AppSettings["Server"], ConfigurationManager.AppSettings["OfferedRentService"]); string postData = "[" + JsonConvert.SerializeObject(offeredRentInput) + "]"; string result = iaziClientsync.postApiRequest(priceUrl, postData, token); parseOfferedRentModelRJson(result, offeredRentOutput); }
private RentData MapRentBuisnessDataToDatabaseModel(string imageBase64, double?latitude, double?longitude, string deviceId, OfferedRentOutput offeredRentOutput) { RentData rentData = new RentData(); if (imageBase64 != null) { rentData.realestateData.Image = imageBase64; if (latitude != null) { rentData.realestateData.Latitude = (decimal)latitude; } if (longitude != null) { rentData.realestateData.Longitude = (decimal)longitude; } using (var ms = new MemoryStream(Convert.FromBase64String(imageBase64))) { System.Drawing.Image img = System.Drawing.Image.FromStream(ms); rentData.realestateData.ImageSize = ms.Length / 1024; rentData.realestateData.ImageWidth = img.Width; rentData.realestateData.ImageHeight = img.Height; } } rentData.realestateData.DeviceId = deviceId; /* Store Address */ rentData.realestateData.AddressZip = offeredRentOutput.zip; rentData.realestateData.AddressTown = offeredRentOutput.town; rentData.realestateData.AddressStreet = offeredRentOutput.street; rentData.realestateData.Country = offeredRentOutput.country; rentData.realestateData.CatCode = offeredRentOutput.CategoryCode; /* Store all calculated values */ rentData.realestateData.SurfaceLiving = offeredRentOutput.surfaceContract; //priceData.realestateData.LandSurface = offeredRentOutput.landSurface; if (offeredRentOutput.qualityMicro != null) { rentData.realestateData.MicroRating = (decimal)offeredRentOutput.qualityMicro; } if (offeredRentOutput.roomNb != null) { rentData.realestateData.RoomNb = (decimal)offeredRentOutput.roomNb; } rentData.realestateData.Lift = offeredRentOutput.lift; rentData.realestateData.ObjectTypeCode = offeredRentOutput.ObjectTypeCode; rentData.realestateData.BuildYear = offeredRentOutput.buildYear; //realEstateAppraise.RealEstateId = new Guid(); rentData.realestateRent.AppraisalValue = offeredRentOutput.appraisalValue; rentData.realestateRent.MinAppraisalValue = offeredRentOutput.minappraisalValue; rentData.realestateRent.MaxAppraisalValue = offeredRentOutput.maxappraisalValue; return(rentData); }
private void parseOfferedRentModelRJson(string resultJson, OfferedRentOutput offeredRentOutput) { dynamic jsonOfferedRentResult = Newtonsoft.Json.JsonConvert.DeserializeObject(resultJson); if (jsonOfferedRentResult.status.Value == "OK" && jsonOfferedRentResult.data[0].result.status.Value == 0) { offeredRentOutput.appraisalValue = (long)jsonOfferedRentResult.data[0].result.value.Value; Random rnd = new Random(); double randomHi = 13 / 100.0; //rnd.Next(10, 15) / 100.0; double randomLow = 17 / 100.0; //rnd.Next(15, 20) / 100.0; if (reverseGeoCodeResult == null || reverseGeoCodeResult.Country == "Switzerland") { offeredRentOutput.minappraisalValue = Convert.ToInt64(offeredRentOutput.appraisalValue - (offeredRentOutput.appraisalValue * randomLow)); offeredRentOutput.maxappraisalValue = Convert.ToInt64(offeredRentOutput.appraisalValue + (offeredRentOutput.appraisalValue * randomHi)); } for (int i = 0; i < jsonOfferedRentResult.data[0].parameterInfo.Count; i++) { dynamic component = jsonOfferedRentResult.data[0].parameterInfo[i]; string compName = component.name; // check if this entry in address_components has a type of country switch (compName) { case "ortId": offeredRentOutput.ortId = (component.value > 0) ? component.value : component.replacedValue; break; case "objectTypeCode": offeredRentOutput.ObjectTypeCode = (component.value > 0) ? component.value : component.replacedValue; break; case "roomNb": offeredRentOutput.roomNb = (component.value > 0) ? component.value : component.replacedValue; break; case "surfaceContract": offeredRentOutput.surfaceContract = (component.value > 0) ? component.value : component.replacedValue; break; //case "surfaceGround": // offeredRentOutput.landSurface = (component.value > 0) ? component.value : component.replacedValue; // break; //case "bathNb": // offeredRentOutput.bathNb = (component.value > 0) ? component.value : component.replacedValue; // break; case "buildYear": offeredRentOutput.buildYear = (component.value > 0) ? component.value : component.replacedValue; break; case "liftNb": offeredRentOutput.lift = (component.value > 0) ? component.value : (component.replacedValue == null) ? 0 : component.replacedValue; break; //case "categoryCode": // offeredRentOutput.CategoryCode = (component.value > 0) ? component.value : (component.replacedValue == null) ? 0 : component.replacedValue; // break; default: break; } } } }
public OfferedRentOutput processImageLatLonForOfferedRent(string imageBase64, double?latitude, double?longitude, string deviceId, string userAgent) { OfferedRentOutput offeredRentOutput = new OfferedRentOutput(); GoogleVisionApi googleVisionApi = new GoogleVisionApi(); OfferedRentInput offeredRentInput = new OfferedRentInput(); ImageCategory imageCategory; string country; string countryCode; try { imageCategory = googleVisionApi.fetchCategoryForImage(imageBase64); } catch (Exception) { //imageBase64 = getImageAndConvertbase64(); //imageCategory = googleVisionApi.fetchCategoryForImage(imageBase64); imageCategory = new ImageCategory(); imageCategory.CategoryCode = -2; imageCategory.CategoryText = "Invalid Image"; } getAddressForLatLong(latitude ?? 0.0, longitude ?? 0.0); if (reverseGeoCodeResult.Country != "Switzerland") { country = "Switzerland"; countryCode = "CH"; offeredRentInput.address = new OfferedRentAddress() { address = ConfigurationManager.AppSettings["DefaultFormatedAddress"], zip = offeredRentOutput.zip = ConfigurationManager.AppSettings["DefaultZip"], town = offeredRentOutput.town = ConfigurationManager.AppSettings["DefaultTown"], street = offeredRentOutput.street = ConfigurationManager.AppSettings["DefaultStreet"] + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second, lat = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLatitude"]), lng = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLongitude"]), country = country }; offeredRentOutput.minappraisalValue = Convert.ToInt64(latitude.ToString().Replace(".", String.Empty)); offeredRentOutput.maxappraisalValue = Convert.ToInt64(longitude.ToString().Replace(".", String.Empty)); } else { country = reverseGeoCodeResult.Country; countryCode = "CH"; offeredRentInput.address = new OfferedRentAddress() { address = reverseGeoCodeResult.FormattedAddress, zip = offeredRentOutput.zip = reverseGeoCodeResult.Zip, town = offeredRentOutput.town = reverseGeoCodeResult.Town, street = offeredRentOutput.street = reverseGeoCodeResult.Street, lat = (double)latitude, lng = (double)longitude, country = country }; } if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2) { getMicroRating(imageCategory.CategoryCode, offeredRentInput.address.lat ?? 0.0, offeredRentInput.address.lng ?? 0.0, countryCode); offeredRentInput.qualityMicro = offeredRentOutput.qualityMicro = ratingResponse.results.microRatingClass1To5 ?? 3; offeredRentInput.ortId = getOrtId(countryCode, offeredRentInput.address.lat ?? 0.0, offeredRentInput.address.lng ?? 0.0, "en-US"); } offeredRentOutput.country = country; offeredRentOutput.CategoryCode = imageCategory.CategoryCode; switch (imageCategory.CategoryCode) { case 5: offeredRentInput.surfaceContract = Convert.ToInt16(ConfigurationManager.AppSettings["A2SurfaceLivingDefault"]); //set default for A2 for Surface offeredRentInput.categoryCode = offeredRentOutput.CategoryCode; offeredRentOutput.category = imageCategory.CategoryText; //" Single family House"; break; case 6: offeredRentInput.surfaceContract = Convert.ToInt16(ConfigurationManager.AppSettings["A3SurfaceLivingDefault"]); offeredRentInput.categoryCode = offeredRentOutput.CategoryCode; offeredRentOutput.category = imageCategory.CategoryText; //" Condominium"; break; case -1: case -2: offeredRentOutput.category = imageCategory.CategoryText; break; default: break; } if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2) { CalculateRent(offeredRentInput, offeredRentOutput); } //Saving Property Details// try { RentData rentData = MapRentBuisnessDataToDatabaseModel(imageBase64, latitude, longitude, deviceId, offeredRentOutput); SaveRentPropertyDetails(rentData, userAgent); } catch (Exception ex) { RealEstateRepository realEstateRepository = new RealEstateRepository(); realEstateRepository.saveException(ex.Message, Convert.ToString(ex.InnerException), ex.StackTrace); return(offeredRentOutput); } return(offeredRentOutput); }