示例#1
0
        private static void DistrictWithAvgPricePerSquareMeter(RealEstateContext context)
        {
            Console.WriteLine("District with average price per m²");

            IDistrictService service = new DistrictService(context);

            var districts = service.DistrictWithAveragePricePerSquareMeter();

            foreach (var district in districts.OrderByDescending(x => x.AveragePricePerSquareMeter))
            {
                Console.WriteLine(district);
            }
        }
示例#2
0
        private static void AddTags()
        {
            var context = new RealEstateContext();

            var tags = new Dictionary <int, Tag>
            {
                { 1, new Tag {
                      Name = "Ново строителство"
                  } },
                { 2, new Tag {
                      Name = "Старо строителство"
                  } },
                { 3, new Tag {
                      Name = "Евтино строителство"
                  } },
                { 4, new Tag {
                      Name = "Скъпо строителство"
                  } },
                { 5, new Tag {
                      Name = "Къща"
                  } },
                { 6, new Tag {
                      Name = "Апартамент"
                  } },
                { 7, new Tag {
                      Name = "Топ оферта"
                  } }
            };

            var properties = context.Properties.Include(x => x.BuildingType)
                             .Include(x => x.PropertyType)
                             .Include(x => x.District)
                             .ToList();

            Stopwatch stopwatch = new Stopwatch();

            foreach (var property in properties)
            {
                stopwatch.Start();

                if (property.Price <= 0 || property.Size <= 0)
                {
                    continue;
                }

                /*
                 * Ново строителство
                 * Старо строителство
                 * Евтино имущество
                 * Скъпо имущество
                 * Къща
                 * Апартамент
                 * Топ оферта
                 */

                if (property.BuildingYear >= 2010)
                {
                    property.AddTag(tags[1]);
                }
                else
                {
                    property.AddTag(tags[2]);
                }

                var service = new DistrictService(context);

                var district = service.DistrictWithAveragePricePerSquareMeter()
                               .FirstOrDefault(x => x.DistrictId == property.DistrictId);

                decimal pricePerSquareMeter = property.Price / (decimal)property.Size;
                decimal districtAveragePricePerSquareMeter = district.AveragePricePerSquareMeter;

                if (pricePerSquareMeter + 100 < districtAveragePricePerSquareMeter)
                {
                    property.AddTag(tags[3]);
                }
                else if (pricePerSquareMeter - 50 > districtAveragePricePerSquareMeter)
                {
                    property.AddTag(tags[4]);
                }

                if (property.BuildingType.Name == "КЪЩА")
                {
                    property.AddTag(tags[5]);
                }
                else
                {
                    property.AddTag(tags[6]);
                }

                if (property.District.Properties.Count >= 10)
                {
                    var topCheapestPropertiesInDistrict = property
                                                          .District
                                                          .Properties
                                                          .ToList()
                                                          .Where(x => x.Price != 0)
                                                          .OrderBy(x => x.Price / (decimal)x.Size)
                                                          .Take(3);

                    if (topCheapestPropertiesInDistrict.Any(x => x.Id == property.Id))
                    {
                        property.AddTag(tags[7]);
                    }
                }

                context.SaveChanges();
            }

            stopwatch.Stop();
            Console.WriteLine($"Data imported for: " + stopwatch.Elapsed); // ~3:30:00 on my PC
        }