public ActionResult DeleteConfirmed(int id) { List <HomeProperties_MetaData> homeProperties_MetaData = _db.HomeProperties_MetaData.Where(a => a.HomePropertyID == id).ToList(); if (homeProperties_MetaData != null) { foreach (var item in homeProperties_MetaData) { _db.HomeProperties_MetaData.Remove(item); } } List <HomeProperty_Galleries> homeProperty_Galleries = _db.HomeProperty_Galleries.Where(a => a.HomePropertyID == id).ToList(); if (homeProperty_Galleries != null) { foreach (var item in homeProperty_Galleries) { _db.HomeProperty_Galleries.Remove(item); } } HomeProperty homeProperty = _db.HomeProperties.Find(id); _db.HomeProperties.Remove(homeProperty); _db.SaveChanges(); return(RedirectToAction("PropertyList")); }
public virtual ActionResult Create(CreatePropertyViewModel _createPropertyViewModel, List <int> checkFacility, List <int> checkCondition, List <HttpPostedFileBase> fileUpload, List <string> DeletedPhotp) { decimal homeprice = 0; decimal rentPrice = 0; decimal mortgagePrice = 0; int locArea = 0; int locAge = 0; string _lat = ""; string _long = ""; if (!string.IsNullOrEmpty(_createPropertyViewModel.HomePrice)) { if (_createPropertyViewModel.HomePrice.Contains(',')) { homeprice = decimal.Parse(_createPropertyViewModel.HomePrice.Replace(",", "")); } else { homeprice = decimal.Parse(_createPropertyViewModel.HomePrice); } } if (!string.IsNullOrEmpty(_createPropertyViewModel.RentPrice)) { if (_createPropertyViewModel.RentPrice.Contains(',')) { rentPrice = decimal.Parse(_createPropertyViewModel.RentPrice.Replace(",", "")); } else { rentPrice = decimal.Parse(_createPropertyViewModel.RentPrice); } } if (!string.IsNullOrEmpty(_createPropertyViewModel.MortgagePrice)) { if (_createPropertyViewModel.MortgagePrice.Contains(',')) { mortgagePrice = decimal.Parse(_createPropertyViewModel.MortgagePrice.Replace(",", "")); } else { mortgagePrice = decimal.Parse(_createPropertyViewModel.MortgagePrice); } } if (!string.IsNullOrEmpty(_createPropertyViewModel.LocArea)) { if (_createPropertyViewModel.LocArea.Contains(',')) { locArea = int.Parse(_createPropertyViewModel.LocArea.Replace(",", "")); } else { locArea = int.Parse(_createPropertyViewModel.LocArea); } } if (!string.IsNullOrEmpty(_createPropertyViewModel.LocAge)) { if (_createPropertyViewModel.LocAge.Contains(',')) { locAge = int.Parse(_createPropertyViewModel.LocAge.Replace(",", "")); } else { locAge = int.Parse(_createPropertyViewModel.LocAge); } } if (!string.IsNullOrEmpty(_createPropertyViewModel.latlongMap)) { _lat = _createPropertyViewModel.latlongMap.Split(',')[0]; _long = _createPropertyViewModel.latlongMap.Split(',')[1]; } int _cultureID = 1; int UserID = 1; List <string> ImageNames = new List <string>(); if (User.Identity.IsAuthenticated) { var res = _db.Users.SingleOrDefault(a => a.UserName == User.Identity.Name); if (res != null) { UserID = res.UserID; } } if (fileUpload[0] == null) { _createPropertyViewModel.ImageName = "home-defualt.png"; ImageNames.Add(_createPropertyViewModel.ImageName); } else { _createPropertyViewModel.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(fileUpload[0].FileName); fileUpload[0].SaveAs(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName); ImageResizer img = new ImageResizer(); img.Resize(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName, Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/Thumb/") + _createPropertyViewModel.ImageName); } switch (System.Globalization.CultureInfo.CurrentCulture.Name) { case "fa-IR": { _cultureID = 1; break; } case "en-US": { _cultureID = 2; break; } } if (_createPropertyViewModel.PropertyTypeID == 1) { rentPrice = 0; mortgagePrice = 0; } else { homeprice = 0; } HomeProperty _homeProperty = new HomeProperty() { CreateDate = DateTime.Now, Title = _createPropertyViewModel.Title, CreateUserID = UserID, SubUsageID = _createPropertyViewModel.SubUsageID, StatusID = (_createPropertyViewModel.PropertyTypeID == 1 ? 1 : 2), RegionID = _createPropertyViewModel.rigionID, CultureID = _cultureID, PropertyTypeID = _createPropertyViewModel.PropertyTypeID, LocAge = locAge, LocArea = locArea, Description = _createPropertyViewModel.Description, HomePrice = homeprice, MortgagePrice = mortgagePrice, RentPrice = rentPrice, ImageName = _createPropertyViewModel.ImageName, LocLatitude = _lat, LocLongitude = _long, PhoneNum = _createPropertyViewModel.PhoneNum }; if (ModelState.IsValid) { _db.HomeProperties.Add(_homeProperty); _db.SaveChanges(); if (fileUpload != null) { foreach (var item in fileUpload) { if (item != null && item.IsImage()) { if (DeletedPhotp != null) { if (DeletedPhotp.Contains(item.FileName)) { continue; } } _createPropertyViewModel.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(item.FileName); ImageNames.Add(_createPropertyViewModel.ImageName); item.SaveAs(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName); ImageResizer img = new ImageResizer(); img.Resize(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName, Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/Thumb/") + _createPropertyViewModel.ImageName); } } } #region facility if (checkFacility != null) { foreach (var item in checkFacility) { _db.HomeProperties_MetaData.Add(new HomeProperties_MetaData() { HomePropertyID = _homeProperty.HomePropertyID, FacilityID = item }); } } #endregion #region condition if (checkCondition != null) { foreach (var item in checkCondition) { _db.HomeProperties_MetaData.Add(new HomeProperties_MetaData() { HomePropertyID = _homeProperty.HomePropertyID, ConditionID = item }); } } #endregion #region ImageGallry if (ImageNames != null) { foreach (var item in ImageNames) { _db.HomeProperty_Galleries.Add(new HomeProperty_Galleries() { HomePropertyID = _homeProperty.HomePropertyID, ImageName = item }); } } #endregion _db.SaveChanges(); Session["InsertProperty"] = true; ModelState.Clear(); } else { Session["NoInsertData"] = true; } ViewBag.CountryID = new SelectList(_db.Countries, "CountryID", "CountryTitle"); ViewBag.PropertyTypeID = new SelectList(_db.HomeProperty_Type, "PropertyTypeID", "Title"); ViewBag.usageID = new SelectList(_db.Usages, "UsageID", "UsageTitle"); ViewBag.Facilities = _db.Facilities.ToList(); ViewBag.Conditions = _db.Conditions.ToList(); return(View()); }
public static bool ParseProperty(string link) { PhantomJSDriver driver = CreateDriver(); try { if (driver.SessionId == null) { driver = CreateDriver(); } //переход по стартовой ссылке города while (true) { try { driver.Navigate().GoToUrl(link); break; } catch (Exception ex) { logger.Trace(ex, "Ошибка получения страницы, время ожидания истекло. {0},{1}", ex.Message, ex.StackTrace); logger.Error(ex, "Ошибка получения страницы, время ожидания истекло. {0},{1}", ex.Message, ex.StackTrace); driver.Quit(); driver = CreateDriver(); } } if (!link.Contains("sold")) { Console.WriteLine("Property isn't sold." + link); logger.Info("Property isn't sold. {0}", link); return(false); } Dictionary <string, object> mainProperties = driver.ExecuteScript("return trulia.pdp.propertyJSON") as Dictionary <string, object>; HomeProperty hp = new HomeProperty(); try { hp.addressForDisplay = (string)mainProperties[Constants.HomePropertyJSObjectKeys.addressForDisplay]; } catch { } try { hp.addressForLeadForm = (string)mainProperties[Constants.HomePropertyJSObjectKeys.addressForLeadForm]; } catch { } try { hp.agentName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.agentName]; } catch { } try { hp.apartmentNumber = (string)mainProperties[Constants.HomePropertyJSObjectKeys.apartmentNumber]; } catch { } try { hp.builderCommunityId = (string)mainProperties[Constants.HomePropertyJSObjectKeys.builderCommunityId]; } catch { } try { hp.builderName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.builderName]; } catch { } try { hp.city = (string)mainProperties[Constants.HomePropertyJSObjectKeys.city]; } catch { } try { hp.communityFloors = null; } catch { }//!!! try { hp.communityOtherFeatures = null; } catch { } //!!! try { hp.county = (string)mainProperties[Constants.HomePropertyJSObjectKeys.county]; } catch { } try { hp.countyFIPS = (string)mainProperties[Constants.HomePropertyJSObjectKeys.countyFIPS]; } catch { } try { hp.dataPhotos = (string)mainProperties[Constants.HomePropertyJSObjectKeys.dataPhotos]; } catch { } try { hp.description = driver.FindElementByCssSelector("#corepropertydescription").Text; } catch { } //!!!!!!!!!!!!!!!! try { hp.directLink = link; } catch { } try { hp.features = driver.FindElementByCssSelector(".mtl").Text; } catch { } //!!!!!!!!!! try { hp.formattedBedAndBath = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedBedAndBath]; } catch { } try { hp.formattedLotSize = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedLotSize]; } catch { } try { hp.formattedPrice = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedPrice]; } catch { } try { hp.formattedSqft = (string)mainProperties[Constants.HomePropertyJSObjectKeys.formattedSqft]; } catch { } try { hp.hasOpenHouse = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.hasOpenHouse]; } catch { } try { hp.hasPhotos = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.hasPhotos]; } catch { } try { hp.HomeDetails = null; } catch { } //!!!! try { hp.idealIncome = -1; } catch { } //!!!! try { hp.indexSource = (string)mainProperties[Constants.HomePropertyJSObjectKeys.indexSource]; } catch { } try { hp.isBuilder = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isBuilder]; } catch { } try { hp.isBuilderCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isBuilderCommunity]; } catch { } try { hp.isForeclosure = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isForeclosure]; } catch { } try { hp.isForSale = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isForSale]; } catch { } try { hp.isPlan = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isPlan]; } catch { } try { hp.isPromotedCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isPromotedCommunity]; } catch { } try { hp.isRealogy = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRealogy]; } catch { } try { hp.isRental = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRental]; } catch { } try { hp.isRentalCommunity = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isRentalCommunity]; } catch { } try { hp.isSpec = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSpec]; } catch { } try { hp.isSrpFeatured = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSrpFeatured]; } catch { } try { hp.isStudio = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isStudio]; } catch { } try { hp.isSubsidized = (bool)mainProperties[Constants.HomePropertyJSObjectKeys.isSubsidized]; } catch { } try { hp.lastSaleDate = (string)mainProperties[Constants.HomePropertyJSObjectKeys.lastSaleDate]; } catch { } try { hp.latitude = (double)mainProperties[Constants.HomePropertyJSObjectKeys.latitude]; } catch { } try { hp.listingId = (long)mainProperties[Constants.HomePropertyJSObjectKeys.listingId]; } catch { } try { hp.listingType = (string)mainProperties[Constants.HomePropertyJSObjectKeys.listingType]; } catch { } try { hp.locationId = (string)mainProperties[Constants.HomePropertyJSObjectKeys.locationId]; } catch { } try { hp.longitude = (double)mainProperties[Constants.HomePropertyJSObjectKeys.longitude]; } catch { } try { hp.metaInfo = null; } catch { }//!!!! try { hp.numBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBathrooms]); } catch { } try { hp.numBedrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBedrooms]); } catch { } try { hp.numBeds = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numBeds]); } catch { } try { hp.numFullBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numFullBathrooms]); } catch { } try { hp.numPartialBathrooms = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.numPartialBathrooms]); } catch { } try { hp.pdpURL = (string)mainProperties[Constants.HomePropertyJSObjectKeys.pdpURL]; } catch { } try { hp.PetsAllowed = null; } catch { } // !!!!!!!!!!! try { hp.phone = null; } catch { } //!!!!!!! try { hp.postId = (long)mainProperties[Constants.HomePropertyJSObjectKeys.postId]; } catch { } try { hp.pricePerSqft = (string)mainProperties[Constants.HomePropertyJSObjectKeys.pricePerSqft]; } catch { } try { hp.PublicRecords = null; } catch { }//!!!!!! try { hp.rentalPartnerDisplayText = (string)mainProperties[Constants.HomePropertyJSObjectKeys.rentalPartnerDisplayText]; } catch { } try { hp.type = (string)mainProperties[Constants.HomePropertyJSObjectKeys.type]; } catch { } try { hp.typeDisplay = (string)mainProperties[Constants.HomePropertyJSObjectKeys.typeDisplay]; } catch { } try { hp.shortDescription = (string)mainProperties[Constants.HomePropertyJSObjectKeys.shortDescription]; } catch { } try { hp.sqft = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.sqft]); } catch { } try { hp.stateCode = (string)mainProperties[Constants.HomePropertyJSObjectKeys.stateCode]; } catch { } try { hp.stateName = (string)mainProperties[Constants.HomePropertyJSObjectKeys.stateName]; } catch { } try { hp.status = (string)mainProperties[Constants.HomePropertyJSObjectKeys.status]; } catch { } try { hp.street = (string)mainProperties[Constants.HomePropertyJSObjectKeys.street]; } catch { } try { hp.streetNumber = (string)mainProperties[Constants.HomePropertyJSObjectKeys.streetNumber]; } catch { } try { hp.yearBuilt = Convert.ToInt32(mainProperties[Constants.HomePropertyJSObjectKeys.yearBuilt]); } catch { } try { hp.zipCode = (string)mainProperties[Constants.HomePropertyJSObjectKeys.zipCode]; } catch { } try { hp.ComparablesJSON = (string)driver.ExecuteScript("return JSON.stringify(trulia.pdp.comparableProperties)"); } catch { } long ID = hp.InsertToDb(); if (ID > 0) { List <PropertyCrime> crimes = GetCrimes(driver, ID); crimes.ForEach(crime => crime.InsertToDb()); } if (ID > 0) { List <PropertySchool> schools = GetSchools(driver, ID); schools.ForEach(school => school.InsertToDb()); } return(true); //все прошло успешно } catch (OpenQA.Selenium.WebDriverException ex) { logger.Error(ex, "Возникло исключение web-драйвера: {1}, {0}", ex.StackTrace, ex.Message); return(false); } catch (Exception ex) { logger.Error(ex, "Возникло неизвестное исключение: {1}, {0}", ex.StackTrace, ex.Message); return(false); } finally { driver.Quit(); } }