Exemplo n.º 1
0
        public void Copy(Listing newListing)
        {
            if (newListing == null)
            {
                throw new ArgumentNullException("newListing");
            }

            if (!newListing.IsModified)
            {
                return;
            }

            base.Copy(newListing);

            if (newListing.IsAgencyIdModified)
            {
                AgencyId = newListing.AgencyId;
            }

            if (newListing.IsStatusTypeModified)
            {
                StatusType = newListing.StatusType;
            }

            if (newListing.IsCreatedOnModified)
            {
                CreatedOn = newListing.CreatedOn;
            }

            if (newListing.IsTitleModified)
            {
                Title = newListing.Title;
            }

            if (newListing.IsDescriptionModified)
            {
                Description = newListing.Description;
            }

            if (newListing.IsAddressModified)
            {
                if (newListing.Address == null)
                {
                    Address = null;
                }
                else
                {
                    if (Address == null)
                    {
                        Address = new Address();
                    }

                    if (newListing.Address.IsModified)
                    {
                        Address.Copy(newListing.Address);
                    }

                    IsAddressModified = true;
                }
            }

            if (newListing.IsAgentsModified)
            {
                if (newListing.Agents == null)
                {
                    Agents = null;
                }
                else
                {
                    Agents = new List<ListingAgent>();
                    foreach (var newAgent in newListing.Agents)
                    {
                        var agent = new ListingAgent();
                        agent.Copy(newAgent);
                        Agents.Add(agent);
                    }
                }
            }

            if (newListing.IsImagesModified)
            {
                if (newListing.Images == null)
                {
                    Images = null;
                }
                else
                {
                    Images = new List<Media>();
                    foreach (var newImage in newListing.Images)
                    {
                        var image = new Media();
                        image.Copy(newImage);
                        Images.Add(image);
                    }
                }
            }

            if (newListing.IsFloorPlansModified)
            {
                if (newListing.FloorPlans == null)
                {
                    FloorPlans = null;
                }
                else
                {
                    FloorPlans = new List<Media>();
                    foreach (var newFloorPlan in newListing.FloorPlans)
                    {
                        var floorPlan = new Media();
                        floorPlan.Copy(newFloorPlan);
                        FloorPlans.Add(floorPlan);
                    }
                }
            }

            if (newListing.IsVideosModified)
            {
                if (newListing.Videos == null)
                {
                    Videos = null;
                }
                else
                {
                    Videos = new List<Media>();
                    foreach (var newVideo in newListing.Videos)
                    {
                        var video = new Media();
                        video.Copy(newVideo);
                        Videos.Add(video);
                    }
                }
            }

            if (newListing.IsInspectionsModified)
            {
                if (newListing.Inspections == null)
                {
                    Inspections = null;
                }

                else
                {
                    Inspections = new List<Inspection>();
                    foreach (var newInspection in newListing.Inspections)
                    {
                        var inspection = new Inspection();
                        inspection.Copy(newInspection);
                        Inspections.Add(inspection);
                    }

                }
            }

            if (newListing.IsLandDetailsModified)
            {
                if (newListing.LandDetails == null)
                {
                    LandDetails = null;
                }
                else
                {
                    if (LandDetails == null)
                    {
                        LandDetails = new LandDetails();
                    }

                    if (newListing.LandDetails.IsModified)
                    {
                        LandDetails.Copy(newListing.LandDetails);
                    }

                    IsLandDetailsModified = true;
                }
            }

            if (newListing.IsFeaturesModified)
            {
                if (newListing.Features == null)
                {
                    Features = null;
                }
                else
                {
                    if (Features == null)
                    {
                        Features = new Features();
                    }

                    if (newListing.Features.IsModified)
                    {
                        Features.Copy(newListing.Features);
                    }

                    IsFeaturesModified = true;
                }
            }

            if (newListing.IsLinksModified)
            {
                Links = newListing.Links == null
                    ? null
                    : new List<string>(newListing.Links);
            }
        }
            private static void AssertFeatures(Features features,
                IList<string> tags,
                bool isModified,
                int bedroomsCount = 0,
                int bathroomCount = 0,
                int ensuitesCount = 0,
                int toiletsCount = 0,
                int livingAreasCount = 0,
                CarParking carParking = null)
            {
                features.Bedrooms.ShouldBe(bedroomsCount);
                features.IsBedroomsModified.ShouldBe(isModified);
                features.Bathrooms.ShouldBe(bathroomCount);
                features.IsBathroomsModified.ShouldBe(isModified);
                features.Ensuites.ShouldBe(ensuitesCount);
                features.IsEnsuitesModified.ShouldBe(isModified);
                features.Toilets.ShouldBe(toiletsCount);
                features.IsToiletsModified.ShouldBe(isModified);
                features.LivingAreas.ShouldBe(livingAreasCount);
                features.IsLivingAreasModified.ShouldBe(isModified);

                if (tags != null)
                {
                    AssertTags(features.Tags, tags);
                }

                if (features.CarParking != null)
                {
                    AssertCarParking(features.CarParking, carParking, isModified);
                }
                features.IsCarParkingModified.ShouldBe(isModified);

                features.IsTagsModified.ShouldBe(isModified);
            }
Exemplo n.º 3
0
        public override void ClearAllIsModified()
        {
            base.ClearAllIsModified();

            if (Address != null)
            {
                Address.ClearAllIsModified();
            }
            IsAddressModified = false;

            if (Agents != null)
            {
                foreach (var agent in Agents)
                {
                    agent.ClearAllIsModified();
                }
            }
            IsAgentsModified = false;

            if (Images != null)
            {
                foreach (var image in Images)
                {
                    image.ClearAllIsModified();
                }
            }
            IsImagesModified = false;

            if (FloorPlans != null)
            {
                foreach (var floorPlan in FloorPlans)
                {
                    floorPlan.ClearAllIsModified();
                }
            }
            IsFloorPlansModified = false;

            if (Videos != null)
            {
                foreach (var video in Videos)
                {
                    video.ClearAllIsModified();
                }
            }
            IsVideosModified = false;

            if (Inspections != null)
            {
                foreach (var inspection in Inspections)
                {
                    inspection.ClearAllIsModified();
                }
            }

            if (LandDetails != null)
            {
                LandDetails.ClearAllIsModified();
            }
            IsLandDetailsModified = false;

            if (Features != null)
            {
                Features.ClearAllIsModified();
            }
            IsFeaturesModified = false;

            IsAgencyIdModified    = false;
            IsStatusTypeModified  = false;
            IsCreatedOnModified   = false;
            IsTitleModified       = false;
            IsDescriptionModified = false;
            IsInspectionsModified = false;
            IsLinksModified       = false;
        }
Exemplo n.º 4
0
        public void Copy(Listing newListing)
        {
            if (newListing == null)
            {
                throw new ArgumentNullException("newListing");
            }

            if (!newListing.IsModified)
            {
                return;
            }

            base.Copy(newListing);

            if (newListing.IsAgencyIdModified)
            {
                AgencyId = newListing.AgencyId;
            }

            if (newListing.IsStatusTypeModified)
            {
                StatusType = newListing.StatusType;
            }

            if (newListing.IsCreatedOnModified)
            {
                CreatedOn = newListing.CreatedOn;
            }

            if (newListing.IsTitleModified)
            {
                Title = newListing.Title;
            }

            if (newListing.IsDescriptionModified)
            {
                Description = newListing.Description;
            }

            if (newListing.IsAddressModified)
            {
                if (newListing.Address == null)
                {
                    Address = null;
                }
                else
                {
                    if (Address == null)
                    {
                        Address = new Address();
                    }

                    if (newListing.Address.IsModified)
                    {
                        Address.Copy(newListing.Address);
                    }

                    IsAddressModified = true;
                }
            }

            if (newListing.IsAgentsModified)
            {
                if (newListing.Agents == null)
                {
                    Agents = null;
                }
                else
                {
                    Agents = new List <ListingAgent>();
                    foreach (var newAgent in newListing.Agents)
                    {
                        var agent = new ListingAgent();
                        agent.Copy(newAgent);
                        Agents.Add(agent);
                    }
                }
            }

            if (newListing.IsImagesModified)
            {
                if (newListing.Images == null)
                {
                    Images = null;
                }
                else
                {
                    Images = new List <Media>();
                    foreach (var newImage in newListing.Images)
                    {
                        var image = new Media();
                        image.Copy(newImage);
                        Images.Add(image);
                    }
                }
            }

            if (newListing.IsFloorPlansModified)
            {
                if (newListing.FloorPlans == null)
                {
                    FloorPlans = null;
                }
                else
                {
                    FloorPlans = new List <Media>();
                    foreach (var newFloorPlan in newListing.FloorPlans)
                    {
                        var floorPlan = new Media();
                        floorPlan.Copy(newFloorPlan);
                        FloorPlans.Add(floorPlan);
                    }
                }
            }

            if (newListing.IsVideosModified)
            {
                if (newListing.Videos == null)
                {
                    Videos = null;
                }
                else
                {
                    Videos = new List <Media>();
                    foreach (var newVideo in newListing.Videos)
                    {
                        var video = new Media();
                        video.Copy(newVideo);
                        Videos.Add(video);
                    }
                }
            }

            if (newListing.IsInspectionsModified)
            {
                if (newListing.Inspections == null)
                {
                    Inspections = null;
                }

                else
                {
                    Inspections = new List <Inspection>();
                    foreach (var newInspection in newListing.Inspections)
                    {
                        var inspection = new Inspection();
                        inspection.Copy(newInspection);
                        Inspections.Add(inspection);
                    }
                }
            }

            if (newListing.IsLandDetailsModified)
            {
                if (newListing.LandDetails == null)
                {
                    LandDetails = null;
                }
                else
                {
                    if (LandDetails == null)
                    {
                        LandDetails = new LandDetails();
                    }

                    if (newListing.LandDetails.IsModified)
                    {
                        LandDetails.Copy(newListing.LandDetails);
                    }

                    IsLandDetailsModified = true;
                }
            }

            if (newListing.IsFeaturesModified)
            {
                if (newListing.Features == null)
                {
                    Features = null;
                }
                else
                {
                    if (Features == null)
                    {
                        Features = new Features();
                    }

                    if (newListing.Features.IsModified)
                    {
                        Features.Copy(newListing.Features);
                    }

                    IsFeaturesModified = true;
                }
            }

            if (newListing.IsLinksModified)
            {
                Links = newListing.Links == null
                    ? null
                    : new List <string>(newListing.Links);
            }
        }
Exemplo n.º 5
0
        public void Copy(Features newFeatures)
        {
            if (newFeatures == null)
            {
                throw new ArgumentNullException("newFeatures");
            }

            if (newFeatures.IsBedroomsModified)
            {
                Bedrooms = newFeatures.Bedrooms;
            }

            if (newFeatures.IsBathroomsModified)
            {
                Bathrooms = newFeatures.Bathrooms;
            }

            if (newFeatures.IsToiletsModified)
            {
                Toilets = newFeatures.Toilets;
            }

            if (newFeatures.IsCarParkingModified)
            {
                if (newFeatures.CarParking == null)
                {
                    CarParking = null;
                }
                else
                {
                    if (CarParking == null)
                    {
                        CarParking = new CarParking();
                    }

                    if (newFeatures.CarParking.IsModified)
                    {
                        CarParking.Copy(newFeatures.CarParking);
                    }

                    IsCarParkingModified = true;
                }
            }

            if (newFeatures.IsEnsuitesModified)
            {
                Ensuites = newFeatures.Ensuites;
            }

            if (newFeatures.IsLivingAreasModified)
            {
                LivingAreas = newFeatures.LivingAreas;
            }

            if (newFeatures.IsTagsModified)
            {
                Tags = newFeatures.Tags;
            }
        }
        private static Features ExtractFeatures(XElement document)
        {
            document.ShouldNotBe(null);

            var featuresElement = document.Element("features");
            if (featuresElement == null)
            {
                return null;
            }

            var tags = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

            // NOTE: Bedrooms can be a number -or- the value 'STUDIO'.
            //       YES - where a number is the logical value, they can now have a string. :cry:
            //       So, if the value is a string, like STUDIO (or anything else), then the
            //       value will be returned as ZERO.
            //       If it's a STUDIO, we'll add that to the feature's tag hash set.
            var bedroomsValue = featuresElement.ValueOrDefault("bedrooms");
            var bedrooms = 0;
            if (!string.IsNullOrWhiteSpace(bedroomsValue))
            {
                if (bedroomsValue.Equals("studio", StringComparison.OrdinalIgnoreCase))
                {
                    // *epic le sigh - yes, we have a text value for (what looks like) a number value.
                    tags.Add("bedroom-studio");
                }
                else
                {
                    bedrooms = featuresElement.ByteValueOrDefault("bedrooms");
                }
            }
            
            ExtractFeatureWithTextValues(featuresElement,
                "heating",
                new[] {"gas", "electric", "GDH", "solid", "other"},
                tags);

            ExtractFeatureWithTextValues(featuresElement,
                "hotWaterService",
                new[] {"gas", "electric", "solar"},
                tags);

            ExtractFeatureWithTextValues(featuresElement,
                "pool",
                new[] { "inground", "aboveground" },
                tags,
                null);

            ExtractFeatureWithTextValues(featuresElement,
                "spa",
                new[] { "inground", "aboveground" },
                tags,
                null);

            ExtractOtherFeatures(featuresElement, tags);

            // Now for the final, tricky part - extracting all the boolean stuff into tags.
            foreach (var feature in new[] {"features", "allowances", "ecoFriendly"}
                .Select(node => document.Element(node))
                .Where(element => element != null).Select(ExtractBooleanFeatures)
                .Where(features => features.Any()).SelectMany(features => features))
            {
                tags.Add(feature);
            }

            var finalFeatures = new Features
            {
                Bedrooms = bedrooms,
                Bathrooms = featuresElement.ByteValueOrDefault("bathrooms"),
                CarParking = new CarParking
                {
                    Garages = featuresElement.BoolOrByteValueOrDefault("garages"),
                    Carports = featuresElement.BoolOrByteValueOrDefault("carports"),
                    OpenSpaces = featuresElement.BoolOrByteValueOrDefault("openSpaces")
                },
                Ensuites = featuresElement.BoolOrByteValueOrDefault("ensuite"),
                Toilets = featuresElement.BoolOrByteValueOrDefault("toilets"),
                LivingAreas = featuresElement.BoolOrByteValueOrDefault("livingAreas"),
                Tags = tags
            };

            return finalFeatures;
        }