Esempio n. 1
0
        private static void MoveData(ISession session)
        {
            var importDist = new Dictionary <int, District>();

            using (var sr = new StreamReader("district.txt", Encoding.UTF8))
            {
                while (!sr.EndOfStream)
                {
                    var data       = sr.ReadLine();
                    var splits     = data.Split(';');
                    var distCode   = Int32.Parse(splits[0]);
                    var distName   = splits[1];
                    var streetName = splits[2];
                    if (importDist.ContainsKey(distCode))
                    {
                        if (importDist[distCode].Streets.All(x => x.Name.ToLower() != streetName.ToLower()))
                        {
                            importDist[distCode].AddStreet(new Street(streetName));
                        }
                    }
                    else
                    {
                        var district = new District(distName);
                        district.AddStreet(new Street(streetName));
                        importDist.Add(distCode, district);
                    }
                }
            }

            foreach (var district in importDist)
            {
                var districtVal = district.Value;
                var existDistr  = session.Query <District>().FirstOrDefault(x => x.Name.ToLower() == districtVal.Name.ToLower());
                if (existDistr == null)
                {
                    session.SaveOrUpdate(districtVal);
                }
                else
                {
                    var distNeedSave = false;
                    foreach (var street in districtVal.Streets)
                    {
                        var existStreet = existDistr.Streets.FirstOrDefault(x => x.Name.ToLower() == street.Name.ToLower());
                        if (existStreet == null)
                        {
                            distNeedSave = true;
                            existDistr.AddStreet(new Street(street.Name));
                        }
                    }
                    if (distNeedSave)
                    {
                        session.SaveOrUpdate(districtVal);
                    }
                }
            }
        }
        private static void AddDicitonaryValue(bool addRealEstate = false)
        {
            var dealVariantEntityNew = new DealVariant("dealVariant1");

            if (dealVariantService.IsValid(dealVariantEntityNew))
            {
                dealVariantService.Save(dealVariantEntityNew);
            }

            var dealVariantEntityNew2 = new DealVariant("dealVariant2");

            if (dealVariantService.IsValid(dealVariantEntityNew2))
            {
                dealVariantService.Save(dealVariantEntityNew2);
            }
            var dealVariantEntityNew3 = new DealVariant("dealVariant2");

            if (dealVariantService.IsValid(dealVariantEntityNew3))
            {
                dealVariantService.Save(dealVariantEntityNew3);
            }

            var districtEntityNew = new District("district1");

            if (districtService.IsValid(districtEntityNew))
            {
                districtService.Save(districtEntityNew);
            }

            var districtEntityNew2 = new District("district2");

            if (districtService.IsValid(districtEntityNew2))
            {
                districtService.Save(districtEntityNew2);
            }
            var districtEntityNew3 = new District("district2");

            if (districtService.IsValid(districtEntityNew3))
            {
                districtService.Save(districtEntityNew3);
            }

            var floorLevelEntityNew = new FloorLevel("floorLevel1");

            if (floorLevelService.IsValid(floorLevelEntityNew))
            {
                floorLevelService.Save(floorLevelEntityNew);
            }

            var floorLevelEntityNew2 = new FloorLevel("floorLevel2");

            if (floorLevelService.IsValid(floorLevelEntityNew2))
            {
                floorLevelService.Save(floorLevelEntityNew2);
            }
            var floorLevelEntityNew3 = new FloorLevel("floorLevel2");

            if (floorLevelService.IsValid(floorLevelEntityNew3))
            {
                floorLevelService.Save(floorLevelEntityNew3);
            }

            var layoutEntityNew = new Layout("layout1");

            if (layoutService.IsValid(layoutEntityNew))
            {
                layoutService.Save(layoutEntityNew);
            }

            var layoutEntityNew2 = new Layout("layout2");

            if (layoutService.IsValid(layoutEntityNew2))
            {
                layoutService.Save(layoutEntityNew2);
            }
            var layoutEntityNew3 = new Layout("layout2");

            if (layoutService.IsValid(layoutEntityNew3))
            {
                layoutService.Save(layoutEntityNew3);
            }

            var materialEntityNew = new Material("material1");

            if (materialService.IsValid(materialEntityNew))
            {
                materialService.Save(materialEntityNew);
            }

            var materialEntityNew2 = new Material("material2");

            if (materialService.IsValid(materialEntityNew2))
            {
                materialService.Save(materialEntityNew2);
            }
            var materialEntityNew3 = new Material("material2");

            if (materialService.IsValid(materialEntityNew3))
            {
                materialService.Save(materialEntityNew3);
            }

            var ownershipEntityNew = new Ownership("ownership1");

            if (ownershipService.IsValid(ownershipEntityNew))
            {
                ownershipService.Save(ownershipEntityNew);
            }

            var ownershipEntityNew2 = new Ownership("ownership2");

            if (ownershipService.IsValid(ownershipEntityNew2))
            {
                ownershipService.Save(ownershipEntityNew2);
            }
            var ownershipEntityNew3 = new Ownership("ownership2");

            if (ownershipService.IsValid(ownershipEntityNew3))
            {
                ownershipService.Save(ownershipEntityNew3);
            }

            var realtorEntityNew = new Realtor("realtor1", "phone");

            if (realtorService.IsValid(realtorEntityNew))
            {
                realtorService.Save(realtorEntityNew);
            }

            var realtorEntityNew2 = new Realtor("realtor2", "phone");

            if (realtorService.IsValid(realtorEntityNew2))
            {
                realtorService.Save(realtorEntityNew2);
            }
            var realtorEntityNew3 = new Realtor("realtor2", "phone");

            if (realtorService.IsValid(realtorEntityNew3))
            {
                realtorService.Save(realtorEntityNew3);
            }

            var sewageEntityNew = new Sewage("sewage1");

            if (sewageService.IsValid(sewageEntityNew))
            {
                sewageService.Save(sewageEntityNew);
            }

            var sewageEntityNew2 = new Sewage("sewage2");

            if (sewageService.IsValid(sewageEntityNew2))
            {
                sewageService.Save(sewageEntityNew2);
            }
            var sewageEntityNew3 = new Sewage("sewage2");

            if (sewageService.IsValid(sewageEntityNew3))
            {
                sewageService.Save(sewageEntityNew3);
            }

            var streetEntityNew = new Street("street1");

            if (streetService.IsValid(streetEntityNew))
            {
                districtEntityNew.AddStreet(streetEntityNew);
                districtService.Save(districtEntityNew);
            }

            var streetEntityNew1 = new Street("street11");

            if (streetService.IsValid(streetEntityNew1))
            {
                districtEntityNew.AddStreet(streetEntityNew1);
                districtService.Save(districtEntityNew);
            }

            var streetEntityNew2 = new Street("street2");

            if (streetService.IsValid(streetEntityNew2))
            {
                districtEntityNew2.AddStreet(streetEntityNew2);
                streetService.Save(streetEntityNew);
            }

            var streetEntityNew3 = new Street("street2");

            if (streetService.IsValid(streetEntityNew3))
            {
                Debug.Assert(false, "Не должан была пройти валидация.");
            }

            var terraceEntityNew = new Terrace("terrace1");

            if (terraceService.IsValid(terraceEntityNew))
            {
                terraceService.Save(terraceEntityNew);
            }

            var terraceEntityNew2 = new Terrace("terrace2");

            if (terraceService.IsValid(terraceEntityNew2))
            {
                terraceService.Save(terraceEntityNew2);
            }
            var terraceEntityNew3 = new Terrace("terrace2");

            if (terraceService.IsValid(terraceEntityNew3))
            {
                terraceService.Save(terraceEntityNew3);
            }

            var toiletTypeEntityNew = new ToiletType("toiletType1");

            if (toiletTypeService.IsValid(toiletTypeEntityNew))
            {
                toiletTypeService.Save(toiletTypeEntityNew);
            }

            var toiletTypeEntityNew2 = new ToiletType("toiletType2");

            if (toiletTypeService.IsValid(toiletTypeEntityNew2))
            {
                toiletTypeService.Save(toiletTypeEntityNew2);
            }
            var toiletTypeEntityNew3 = new ToiletType("toiletType2");

            if (toiletTypeService.IsValid(toiletTypeEntityNew3))
            {
                toiletTypeService.Save(toiletTypeEntityNew3);
            }

            var waterSupplyEntityNew = new WaterSupply("waterSupply1");

            if (waterSupplyService.IsValid(waterSupplyEntityNew))
            {
                waterSupplyService.Save(waterSupplyEntityNew);
            }

            var waterSupplyEntityNew2 = new WaterSupply("waterSupply2");

            if (waterSupplyService.IsValid(waterSupplyEntityNew2))
            {
                waterSupplyService.Save(waterSupplyEntityNew2);
            }
            var waterSupplyEntityNew3 = new WaterSupply("waterSupply2");

            if (waterSupplyService.IsValid(waterSupplyEntityNew3))
            {
                waterSupplyService.Save(waterSupplyEntityNew3);
            }
            if (!addRealEstate)
            {
                return;
            }

            var flat = new Flat
            {
                DealVariant       = dealVariantEntityNew,
                Description       = "decr",
                District          = districtEntityNew,
                Floor             = 3,
                FloorLevel        = floorLevelEntityNew,
                HasVideo          = true,
                KitchenSquare     = 32,
                Layout            = layoutEntityNew,
                Material          = materialEntityNew,
                Ownership         = ownershipEntityNew,
                Price             = 32323,
                Realtor           = realtorEntityNew,
                ResidentialSquare = 323,
                Street            = streetEntityNew,
                SubmitToDomino    = false,
                SubmitToVDV       = true,
                Terrace           = terraceEntityNew,
                TerritorialNumber = "32a",
                ToiletType        = toiletTypeEntityNew,
                TotalFloor        = 32,
                TotalRoomCount    = 5,
                TotalSquare       = 323
            };

            if (flatService.IsValid(flat))
            {
                flatService.Save(flat);
            }

            var room = new Room
            {
                DealVariant       = dealVariantEntityNew,
                Description       = "decr",
                District          = districtEntityNew,
                Floor             = 3,
                FloorLevel        = floorLevelEntityNew,
                HasVideo          = true,
                Layout            = layoutEntityNew,
                Material          = materialEntityNew,
                Ownership         = ownershipEntityNew,
                Price             = 32323,
                Realtor           = realtorEntityNew,
                Street            = streetEntityNew,
                SubmitToDomino    = false,
                SubmitToVDV       = true,
                Terrace           = terraceEntityNew,
                TerritorialNumber = "32a",
                TotalFloor        = 32,
                TotalRoomCount    = 5,
                TotalSquare       = 323,
                RoomCount         = 2
            };

            if (roomService.IsValid(room))
            {
                roomService.Save(room);
            }

            var residence = new Residence
            {
                DealVariant       = dealVariantEntityNew,
                Description       = "decr",
                District          = districtEntityNew,
                Floor             = 3,
                HasVideo          = true,
                Material          = materialEntityNew,
                Ownership         = ownershipEntityNew,
                Price             = 32323,
                Realtor           = realtorEntityNew,
                Street            = streetEntityNew,
                SubmitToDomino    = false,
                SubmitToVDV       = true,
                TerritorialNumber = "32a",
                TotalFloor        = 32,
                TotalSquare       = 323
            };

            if (residenceService.IsValid(residence))
            {
                residenceService.Save(residence);
            }

            var house = new House
            {
                DealVariant       = dealVariantEntityNew,
                Description       = "decr",
                District          = districtEntityNew,
                HasVideo          = true,
                Material          = materialEntityNew,
                Ownership         = ownershipEntityNew,
                Price             = 32323,
                Realtor           = realtorEntityNew,
                Street            = streetEntityNew,
                SubmitToDomino    = false,
                SubmitToVDV       = true,
                TerritorialNumber = "32a",
                TotalFloor        = 32,
                HasBathhouse      = true,
                HasGarage         = true,
                HasGas            = true,
                HouseSquare       = 342,
                PlotSquare        = 123,
                Sewage            = sewageEntityNew,
                WaterSupply       = waterSupplyEntityNew
            };

            if (houseService.IsValid(house))
            {
                houseService.Save(house);
            }
            var plot = new Plot
            {
                DealVariant       = dealVariantEntityNew,
                Description       = "decr",
                District          = districtEntityNew,
                HasVideo          = true,
                Ownership         = ownershipEntityNew,
                Price             = 32323,
                Realtor           = realtorEntityNew,
                Street            = streetEntityNew,
                SubmitToDomino    = false,
                SubmitToVDV       = true,
                TerritorialNumber = "32a",
                PlotSquare        = 123
            };

            if (plotService.IsValid(plot))
            {
                plotService.Save(plot);
            }
        }