示例#1
0
        private static void PropertySearch(RealEstatesDbContext context)
        {
            Console.WriteLine("min price:");
            int minPrice = int.Parse(Console.ReadLine());

            Console.WriteLine("max price:");
            int maxPrice = int.Parse(Console.ReadLine());

            Console.WriteLine("min size:");
            int minSize = int.Parse(Console.ReadLine());

            Console.WriteLine("max size:");
            int maxSize = int.Parse(Console.ReadLine());

            IPropertiesService propertiesService = new PropertiesService(context);

            var properties = propertiesService.Search(minPrice, maxPrice, minSize, maxSize);

            var writer = new StringWriter();

            var serializer = new XmlSerializer(typeof(PropertyInfoDto[]), new XmlRootAttribute("Properties"));

            serializer.Serialize(writer, properties);

            Console.WriteLine(writer.ToString());

            writer.Close();
        }
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            var db = new RealEstateDbContext();
            //db.Database.Migrate();

            IPropertiesService propertiesService = new PropertiesService(db);
            //propertiesService.Create("Dianabad", 100, 2019, 322000000, "4-Staen", "Panelka", 17, 21);

            IDistrictsService districtsService = new DistrictsService(db);

            //var districts = districtsService.GetTopDisctrictsByAveragePrice();
            //foreach (var district in districts)
            //{
            //    Console.WriteLine($"{district.Name} => Price: {district.AveragePrice} ({district.MinPrice} - {district.MaxPrice}) => properties: {district.PropertiesCount}");
            //}
            Console.Write("Min price: ");
            int minPrice = int.Parse(Console.ReadLine());

            Console.Write("Max price: ");
            int maxPrice   = int.Parse(Console.ReadLine());
            var properties = propertiesService.SearchByPrice(minPrice, maxPrice);

            foreach (var property in properties)
            {
                Console.WriteLine($"{property.Price}");
            }
        }
        private static void AddTag(ApplicationDbContext context)
        {
            IPropertiesService propertiesService = new PropertiesService(context);

            Console.WriteLine("Tag name:");
            var tagName = Console.ReadLine();

            Console.WriteLine("Importance (optional):");
            bool isParsed   = int.TryParse(Console.ReadLine(), out int tagImportance);
            int? importance = isParsed ? tagImportance : null;

            //var tags = new string[]
            //{
            //    "скъп-имот",
            //    "евтин-имот",
            //    "нов-имот",
            //    "стар-имот",
            //    "голям-имот",
            //    "малък-имот",
            //    "последен-етаж",
            //    "първи-етаж",
            //};

            ITagService tagService = new TagService(context, propertiesService);

            //foreach (var item in tags)
            //{
            //    var randomImportance = new Random().Next(0, 6);
            //    tagService.Add(item, randomImportance);
            //}

            tagService.Add(tagName, importance);
        }
示例#4
0
        static void Main(string[] args)
        {
            var json       = File.ReadAllText("imot.bg-raw-data-2020-07-23.json");
            var properties = JsonSerializer.Deserialize <IEnumerable <JsonProperty> >(json);
            var db         = new RealEstateDbContext();
            IPropertiesService propertiesService = new PropertiesService(db);

            foreach (var property in properties.Where(p => p.Price > 1000))
            {
                try
                {
                    propertiesService.Create(
                        property.District,
                        property.Size,
                        property.Year,
                        property.Price,
                        property.Type,
                        property.BuildingType,
                        property.Floor,
                        property.TotalFloors);
                }
                catch
                {
                }
            }
        }
示例#5
0
        public async Task EditShouldSucceed()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditPropertiesTestDb").Options;

            using var dbContext = new ApplicationDbContext(options);

            var propertyId   = 5;
            var propertyName = $"Property with ID {propertyId}";

            dbContext.Properties.Add(new Property()
            {
                Id   = propertyId,
                Name = propertyName,
            });
            await dbContext.SaveChangesAsync();

            using var propertyRepository = new EfDeletableEntityRepository <Property>(dbContext);
            var propertiesService = new PropertiesService(propertyRepository);

            var editedName = $"Edited Property with ID {propertyId}";

            var model = new EditPropertiesViewModel()
            {
                Name = editedName,
            };

            var property = propertiesService.EditAsync(propertyId, model);

            var editedPropety = dbContext.Properties.FirstOrDefault(p => p.Id == propertyId);

            Assert.NotNull(editedPropety);
            Assert.Equal(editedName, editedPropety.Name);
        }
示例#6
0
        public async Task CreateShouldSucceed()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreatePropertiesTestDb").Options;

            using var dbContext          = new ApplicationDbContext(options);
            using var propertyRepository = new EfDeletableEntityRepository <Property>(dbContext);
            var propertiesService = new PropertiesService(propertyRepository);

            var model = new CreatePropertiesViewModel()
            {
                Address = "33300 Main st",
                Name    = "Peter",
                Owner   = "Ivan Ivanov",
                Size    = 110,
                Type    = PMStudio.Data.Models.Enum.PropertyType.Residential,
                Images  = new List <IFormFile>(),
            };

            await propertiesService.CreateAsync(model, @"C:\PM.Studio.Images");

            var createdModel = dbContext.Properties.FirstOrDefault(p => p.Name == "Peter");

            Assert.NotNull(createdModel);
        }
示例#7
0
        public async Task DeleteShouldDeleteTheCorrectProperty()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeletePropertiesTestDb").Options;

            using var dbContext = new ApplicationDbContext(options);

            var propertyId   = 4;
            var propertyName = $"Property with ID {propertyId}";

            dbContext.Properties.Add(new Property()
            {
                Id   = propertyId,
                Name = propertyName,
            });
            await dbContext.SaveChangesAsync();

            using var propertyRepository = new EfDeletableEntityRepository <Property>(dbContext);
            var propertiesService = new PropertiesService(propertyRepository);

            var countBefore = dbContext.Properties.Count();

            var property = propertiesService.DeleteAsync(propertyId);

            var countAfter = dbContext.Properties.Count();

            Assert.Equal(countBefore, countAfter + 1);
        }
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            var db = new RealEstateDbContext();

            db.Database.Migrate();

            IPropertiesService propertiesService = new PropertiesService(db);
            var properties = propertiesService.SearchByPrice(0, 200000);

            foreach (var property in properties.Take(3))
            {
                Console.WriteLine($"District: {property.District}, Floor: {property.Floor},Size: {property.Size}, Year: {property.Year}, {property.BuildingType}, {property.PropertyType}");
            }

            //propertiesService.Create(2000, 3, 10, "Manastirski livadi", "mesonet", "brich", 2020, 5000000);
            //propertiesService.UpdateTags(1);

            //IDistrictsService districtService = new DistrictService(db);
            //var districts = districtService.GetTopDistrictsByAveragePrice();

            //foreach (var district in districts)
            //{
            //    Console.WriteLine($"{district.Name} - {district.AveragePrice} ,{district.MinPrice}, {district.MaxPrice}");

            //}
        }
示例#9
0
        override public string ToString()
        {
            StringBuilder sb             = new();
            var           propertyValues = PropertiesService.GetDynamicPropertyValues(this);

            foreach (var propValue in propertyValues)
            {
                dynamic propVal;
                if (propValue.Name == "Type")
                {
                    propVal = Enum.GetName(typeof(SegmentType), propValue.Value);
                }
                else if (propValue.Value is List <string> )
                {
                    foreach (var str in propValue.Value as List <string> )
                    {
                        AppendLine(sb, str, propValue.Name);
                    }
                }
                else
                {
                    propVal = (string)propValue.Value;
                    AppendLine(sb, propVal, propValue.Name);
                }
            }
            return(sb.ToString());
        }
示例#10
0
        private static void PropertySearch(RealEstatesDbContext context)
        {
            Console.Write("Min price:");
            var minPrice = int.Parse(Console.ReadLine());

            Console.Write("Max price:");
            var maxPrice = int.Parse(Console.ReadLine());

            Console.Write("Min size:");
            var minSize = int.Parse(Console.ReadLine());

            Console.Write("Max size:");
            var maxSize = int.Parse(Console.ReadLine());

            var service    = new PropertiesService(context);
            var properties = service.Search(minPrice, maxPrice, minSize, maxSize);

            var serializer = new XmlSerializer(typeof(List <PropertyInfoDto>), new XmlRootAttribute("Properties"));

            var namespacesSettings = new XmlSerializerNamespaces();

            namespacesSettings.Add("", "");

            var textWriter = new StringWriter();

            serializer.Serialize(textWriter, properties, namespacesSettings);

            Console.WriteLine(textWriter.ToString().TrimEnd());
        }
        public async Task GetPropertiesForUserShouldReturnOnlyPropertiesThatBelongsToTheUser()
        {
            var db = GetDatabase();

            AutoMapperConfig.RegisterMappings(typeof(VisualisePropertiesViewModel).Assembly);
            var property = new Property()
            {
                Id   = 1,
                Name = "Name",
            };
            var property2 = new Property()
            {
                Id   = 2,
                Name = "Name",
            };
            var property3 = new Property()
            {
                Id   = 3,
                Name = "Name",
            };
            var propertiesRepository = new EfDeletableEntityRepository <Property>(db);

            var service = new PropertiesService(propertiesRepository);
            await db.Properties.AddRangeAsync(property, property2, property3);

            await db.SaveChangesAsync();

            var lol = service.GetProperties <VisualisePropertiesViewModel>(2);

            Assert.Equal(2, lol.Count());
        }
示例#12
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            var db = new RealEstateDbContext();

            db.Database.Migrate();

            IPropertiesService propertiesService = new PropertiesService(db);

            Console.Write("Min price: ");
            int minPrice = int.Parse(Console.ReadLine());

            Console.Write("Max price: ");
            int maxPrice = int.Parse(Console.ReadLine());

            var properties = propertiesService.SearchByPrice(minPrice, maxPrice);

            foreach (var property in properties)
            {
                Console.WriteLine($"{property.District}, fl. {property.Floor}, {property.Size} m², {property.Year}, {property.Price}€, {property.PropertyType}, {property.BuildingType}");
            }
            //IDistrictsService districtService = new DistrictsService(db);
            //var districts = districtService.GetTopDistrictsByAveragePrice();

            //foreach (var district in districts)
            //{
            //    Console.WriteLine($"{district.Name} => Price: {district.AveragePrice} ({district.MinPrice} - {district.MaxPrice}) => {district.PropertiesCount} properties");
            //}
        }
        public async Task EditAsync_SouldReturn_True_IfInputDataIsCorrect()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstProp = new Property {
                Id = 1, IsActual = true, Description = "A lot of"
            };
            var secondProp = new Property {
                Id = 2, IsActual = true, Description = "None"
            };

            await db.Properties.AddRangeAsync(firstProp, secondProp);

            await db.SaveChangesAsync();

            var propertyService = new PropertiesService(mapper, db);

            //Act
            var result = await propertyService.EditAsync(1, "Not Active", false);

            var editedProperty = await db.Properties.FirstOrDefaultAsync(x => x.Id == 1);

            //Assert
            result
            .Should()
            .BeTrue();

            editedProperty
            .Should()
            .BeOfType <Property>()
            .And
            .Match <Property>(p => p.IsActual == false &&
                              p.Description == "Not Active");
        }
示例#14
0
        private static void PropertySearch(ApplicationDbContext context)
        {
            Console.Clear();
            Console.WriteLine("Property Search:");
            Console.Write("Min price:");
            int minPrice = int.Parse(Console.ReadLine());

            Console.Write("Max price:");
            int maxPrice = int.Parse(Console.ReadLine());

            Console.Write("Min size:");
            int minSize = int.Parse(Console.ReadLine());

            Console.Write("Max size:");
            int maxSize = int.Parse(Console.ReadLine());

            IPropertiesService service = new PropertiesService(context);
            var properties             = service.Search(minPrice, maxPrice, minSize, maxSize);

            foreach (var property in properties)
            {
                Console.WriteLine($"{property.DistrictName} ; {property.BuildingType}; " +
                                  $"{property.PropertyType} => {property.Price:F2}€ => {property.Size}m²");
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            var    db   = new RealEstatesDbContext();
            string json = File.ReadAllText("imot.bg-raw-data-2020-07-23.json");
            var    importedProperties = JsonConvert.DeserializeObject <IEnumerable <ImportInfoDTO> >(json);

            var propService = new PropertiesService(db);

            foreach (var prop in importedProperties)
            {
                try
                {
                    propService.Create
                    (
                        prop.Size,
                        prop.Floor,
                        prop.TotalFloors,
                        prop.District,
                        prop.Year,
                        prop.Type,
                        prop.BuildingType,
                        prop.Price
                    );
                }
                catch
                {
                }
            }
        }
示例#16
0
        private static void GetFullDataAboutProperties(ApplicationDbContext db)
        {
            IPropertiesService service = new PropertiesService(db);


            Console.Write("Count of properties:");
            bool parse = int.TryParse(Console.ReadLine(), out int count);

            if (!parse)
            {
                return;
            }

            var fullData = service.GetFullData(count).ToList();

            var serializer =
                new XmlSerializer(typeof(List <PropertyFullInfoDTO>), new XmlRootAttribute("Properties"));

            var sb = new StringBuilder();

            var ns = new XmlSerializerNamespaces();

            ns.Add("", "");



            serializer.Serialize(new StringWriter(sb), fullData, ns);



            Console.WriteLine(sb.ToString());
        }
示例#17
0
        private static void PropertySearch(RealEstateContext context)
        {
            Console.Write("Min price:");
            int minPrice = int.Parse(Console.ReadLine());

            Console.Write("Max price:");
            int maxPrice = int.Parse(Console.ReadLine());

            Console.Write("Min size:");
            int minSize = int.Parse(Console.ReadLine());

            Console.Write("Max size:");
            int maxSize = int.Parse(Console.ReadLine());

            IPropertiesService service = new PropertiesService(context);

            var properties = service.Search(minPrice, maxPrice, minSize, maxSize);

            int count = 0;

            foreach (var property in properties.Where(x => x.Price > 0))
            {
                Console.WriteLine($"{++count}. {property}");
            }
        }
        public async Task AllActiveAsync_SouldReturn_EmptyCollection_IfAppPrpertiesAreNotActiveInDb()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstProp = new Property {
                Id = 1, Name = "Голям склад", Area = 400, IsActual = false
            };
            var secondProp = new Property {
                Id = 2, Name = "Голям склад", Area = 300, IsActual = false
            };
            var thirdProp = new Property {
                Id = 3, Name = "Офис", Area = 80, IsActual = false
            };
            var forthProp = new Property {
                Id = 4, Name = "Стая", Area = 20, IsActual = false
            };
            await db.Properties.AddRangeAsync(firstProp, secondProp, thirdProp, forthProp);

            await db.SaveChangesAsync();

            var propertyService = new PropertiesService(mapper, db);

            var result = await propertyService.AllActiveAsync();

            result
            .Should()
            .BeEmpty();
        }
        public async Task GetAsync_SouldReturn_Null_IfPropertyDoNotExist()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstProp = new Property
            {
                Id          = 1,
                IsActual    = true,
                Description = "A lot of",
                Address     = "Drujba",
                Name        = "Warehouse",
                Area        = 300,
                Type        = PropertyType.Warehouse
            };
            var secondProp = new Property {
                Id = 2, IsActual = true, Description = "None"
            };
            await db.Properties.AddRangeAsync(firstProp, secondProp);

            await db.SaveChangesAsync();

            var propertyService = new PropertiesService(mapper, db);

            //Act
            var result = await propertyService.GetAsync(3);

            //Assert
            result
            .Should()
            .BeNull();
        }
        public async Task EditAsync_SouldReturn_False_IfPropertyDoNotExist()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstProp = new Property {
                Id = 1, IsActual = true, Description = "A lot of"
            };
            var secondProp = new Property {
                Id = 2, IsActual = true, Description = "None"
            };

            await db.Properties.AddRangeAsync(firstProp, secondProp);

            await db.SaveChangesAsync();

            var propertyService = new PropertiesService(mapper, db);

            //Act
            var result = await propertyService.EditAsync(3, "Not Active", false);

            var editedProperty = await db.Properties.FirstOrDefaultAsync(x => x.Id == 3);

            //Assert
            result
            .Should()
            .BeFalse();

            editedProperty
            .Should()
            .BeNull();
        }
示例#21
0
        public static void Main(string[] args)
        {
            var db = new RealEstateDbContext();

            using (db)
            {
                db.Database.Migrate();

                IPropertiesService propertiesService = new PropertiesService(db);

                //propertiesService.Create("Dianabad", "5-Rooms", "Brick", 2019, 210000, 100, 5, 12);

                //propertiesService.UpdateTags(2);
                //propertiesService.UpdateTags(3);

                IDistrictsService districtsService = new DistrictsService(db);

                var districts = districtsService.GetTopDistrictsByAveragePrice();

                foreach (var district in districts)
                {
                    Console.WriteLine($"{district.Name} => {district.AveragePrice:f2} ({district.MinPrice} - {district.MaxPrice}) => {district.PropertiesCount} properties");
                }
            }
        }
        public async Task GetByIdShouldWorkCorretly()
        {
            AutoMapperConfig.RegisterMappings(typeof(VisualisePropertiesViewModel).Assembly);

            var db       = GetDatabase();
            var property = new Property()
            {
                Id   = 1,
                Name = "Name",
            };
            var property2 = new Property()
            {
                Id   = 2,
                Name = "Name",
            };

            var propertiesRepository = new EfDeletableEntityRepository <Property>(db);

            var service = new PropertiesService(propertiesRepository);

            await db.Properties.AddAsync(property);

            await db.SaveChangesAsync();

            var lol = service.GetById <VisualisePropertiesViewModel>(1);

            Assert.Equal(1, lol.Id);
        }
示例#23
0
        private static void AveragePricePerSquareMeter(ApplicationDbContext context)
        {
            IPropertiesService service      = new PropertiesService(context);
            var averagePricePerSquareMiters = service.AveragePricePerSquareMeter();

            Console.WriteLine($"Average price per square meters is : {averagePricePerSquareMiters:F2} €/m².");
            Console.WriteLine("The price doesn't contains houses!");
        }
        public async Task CreateAsync_SouldReturn_True_IfInputDataIsCorrectFromDb()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();


            var firstProp = new Property
            {
                Id       = 3,
                Name     = "Голям склад",
                Area     = 400,
                IsActual = true
            };
            var companyOne = new Company
            {
                Id         = 1,
                Name       = "First",
                Properties = new List <Property>()
                {
                    firstProp
                }
            };
            await db.Companies.AddRangeAsync(companyOne);

            await db.SaveChangesAsync();

            var propertyService = new PropertiesService(mapper, db);
            var model           = new CreatePropertyModel
            {
                CompanyId       = 1,
                PropertyName    = "Office",
                Description     = "No Descriprion",
                Area            = 80,
                Type            = PropertyType.Office,
                PropertyAddress = "Mars"
            };

            //Act
            var result = await propertyService.CreateAsync(model);

            var addedProperty = await db.Properties.FirstOrDefaultAsync(x => x.Name == "Office");

            //Assert
            result
            .Should()
            .BeTrue();

            addedProperty
            .Should()
            .NotBeNull()
            .And
            .BeOfType <Property>()
            .And
            .Match <Property>(p => p.Type == PropertyType.Office &&
                              p.Address == "Mars" &&
                              p.Area == 80 &&
                              p.CompanyId == 1);
        }
示例#25
0
        private static void AddTagsToProperty(RealEstatesDbContext context)
        {
            Console.WriteLine("Adding tags to properties started!");
            IPropertiesService propertiesService = new PropertiesService(context);
            ITagsService       tagsService       = new TagsService(context, propertiesService);

            tagsService.BulkAddTagsToProperty();
            Console.WriteLine("Adding tags to properties finished!");
        }
示例#26
0
        private static void BulkTagToProperties(ApplicationDbContext db)
        {
            Console.WriteLine("Bulk operation started!");
            IPropertiesService propertiesService = new PropertiesService(db);
            ITagService        tagService        = new TagService(db, propertiesService);

            tagService.BulkTagToPropertiesRelation();
            Console.WriteLine("Bulk operation finished!");
        }
示例#27
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var db = new RealEstateDBContext();

            db.Database.Migrate();

            IPropertiesService propertiesService = new PropertiesService(db);
        }
示例#28
0
        private static void BulkTagsToProperties(RealEstatesDbContext context)
        {
            Console.WriteLine("Bulk operation started...");
            var propertyService = new PropertiesService(context);
            var service         = new TagsService(context, propertyService);

            service.BulkTagToProperties();
            Console.WriteLine("Bulk operation finished successfully!");
        }
示例#29
0
        private static void BulkTagsToProperties(ApplicationDbContext context)
        {
            Console.Clear();
            Console.WriteLine("Bulk operation started!");
            IPropertiesService propertiesService = new PropertiesService(context);
            ITagService        tagService        = new TagService(context, propertiesService);

            tagService.BulkTagToProperties();
            Console.WriteLine("Bulk operation finished!");
        }
示例#30
0
        private static void AddCustomPropertiesToDatabase(RealEstateDbContext db)
        {
            IPropertiesService propertiesService = new PropertiesService(db);

            propertiesService.Create(125, 6, 6, "Дианабад", "4-СТАЕН", "Tyxла", 2021, 2000000);

            propertiesService.UpdateTags(1);
            propertiesService.UpdateTags(2);
            propertiesService.UpdateTags(3);
        }