public static void Main(string[] args) { var provider = new ZillowListingsFeed(); var context = new CMDRealContext(); var companies = context.Companies.ToList(); foreach (var company in companies) { var urls = context.SearchUrls.Where(x => x.Company.Id == company.Id).ToList(); foreach (var searchUrl in urls) { var results = provider.Properties(searchUrl.Url); if (results != null) { Console.Clear(); foreach (var property in results) { var existingProperty = context.Properties.FirstOrDefault(x => x.Address.ToLower() == property.Address.ToLower()); if (existingProperty == null) { property.CompanyId = company.Id; property.AssignedStatus = Status.Active; property.StatusDate = DateTime.Now; property.CreatedBy = "Console"; property.ModifiedBy = "Console"; context.Properties.Add(property); context.SaveChanges(); Console.WriteLine(property.Address); provider.PostMessage(property, string.Format("New property found in search results, take a look at {0}", property.Address), MessageType.Info ); } } } } // next pull property details to analyze var properties = context.Properties.Include("Company").ToList(); foreach (var property in properties) { provider.GetSearchResults(property); } } //Console.ReadLine(); }
public void PostMessage(Property property, string msg, MessageType type) { var context = new CMDRealContext(); context.Messages.Add(new Message { CompanyId = property.Company.Id, Date = DateTime.Now, Type = type, Body = msg, RelativePath = "/Property/details/" + property.Id, CreatedBy = "Console", ModifiedBy = "Console", }); context.SaveChanges(); }