public static ValidationResult Validate(Listing listing, bool isTheMinimumDataToStoreAListing = true)
        {
            if (listing is ResidentialListing)
            {
                var validator = new ResidentialListingValidator();
                return isTheMinimumDataToStoreAListing
                    ? validator.Validate(listing as ResidentialListing, ruleSet: ResidentialListingValidator.MinimumRuleSet)
                    : validator.Validate(listing as ResidentialListing);
            }

            if (listing is RentalListing)
            {
                var validator = new RentalListingValidator();
                return isTheMinimumDataToStoreAListing
                    ? validator.Validate(listing as RentalListing, ruleSet: RentalListingValidator.MinimumRuleSet)
                    : validator.Validate(listing as RentalListing);
            }

            if (listing is RuralListing)
            {
                var validator = new RuralListingValidator();
                return isTheMinimumDataToStoreAListing
                    ? validator.Validate(listing as RuralListing, ruleSet: RuralListingValidator.MinimumRuleSet)
                    : validator.Validate(listing as RuralListing);;
            }

            if (listing is LandListing)
            {
                var validator = new LandListingValidator();
                return isTheMinimumDataToStoreAListing
                    ? validator.Validate(listing as LandListing, ruleSet: LandListingValidator.MinimumRuleSet)
                    : validator.Validate(listing as LandListing);
            }

            var errorMessage =
                string.Format(
                    "Tried to validate an unhandled Listing type: {0}. Only Residental, Rental, Rural and Land listing types are supported.",
                    listing.GetType());
            throw new Exception(errorMessage);
        }
Ejemplo n.º 2
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 UpdateListingWithFakeData(Listing listing)
        {
            if (listing == null)
            {
                throw new ArgumentNullException("listing");
            }

            UpdateAggregateRootWithFakeData(listing);

            listing.Agents = new List<ListingAgent>
            {
                new ListingAgent
                {
                    Name = "Princess Leia",
                    Order = 1,
                    Communications = new List<Communication>
                    {
                        new Communication
                        {
                            CommunicationType = CommunicationType.Email,
                            Details = "*****@*****.**"
                        }
                    }
                },
                new ListingAgent
                {
                    Name = "Han Solo",
                    Order = 1,
                    Communications = new List<Communication>
                    {
                        new Communication
                        {
                            CommunicationType = CommunicationType.Email,
                            Details = "*****@*****.**"
                        }
                    }
                }
            };
            listing.Address = new Address
            {
                CountryIsoCode = "AU",
                IsStreetDisplayed = true,
                Latitude = 1.23m,
                Longitude = 3.45m,
                Municipality = "some municipality",
                Postcode = "1234a",
                State = "VIC",
                Street = "Some Street",
                StreetNumber = "69",
                Suburb = "Some Suburb"
            };
            listing.AgencyId = "ABCD-1234";
            listing.CreatedOn = new DateTime(2015, 5, 1);
            listing.Description = "Some description";
            listing.Features = new Features
            {
                Bathrooms = 1,
                Bedrooms = 2,
                CarParking = new CarParking
                {
                    Garages = 5,
                    Carports = 3,
                    OpenSpaces = 7
                },
                Ensuites = 4,
                LivingAreas = 6,

                Toilets = 8,
                Tags = new HashSet<string>(new[] {"z", "y", "x", "w"})
            };
            listing.FloorPlans = new List<Media>
            {
                new Media
                {
                    Url = "http://a.b.c/floorplan1",
                    Order = 1,
                    Tag = "fp1"
                },
                new Media
                {
                    Url = "http://a.b.c/floorplan2",
                    Order = 2,
                    Tag = "fp2"
                }
            };
            listing.Images = new List<Media>
            {
                new Media
                {
                    Url = "http://a.b.c/image1",
                    Order = 1,
                    Tag = "img1"
                },
                new Media
                {
                    Url = "http://a.b.c/image2",
                    Order = 2,
                    Tag = "img2"
                },
                new Media
                {
                    Url = "http://a.b.c/image3",
                    Order = 3,
                    Tag = "img3"
                }
            };
            listing.Inspections = new List<Inspection>
            {
                new Inspection
                {
                    OpensOn = new DateTime(2015, 5, 5, 11, 55, 00),
                    ClosesOn = new DateTime(2015, 5, 5, 13, 00, 00)
                },
                new Inspection
                {
                    OpensOn = new DateTime(2015, 5, 6, 11, 55, 00),
                    ClosesOn = new DateTime(2015, 5, 6, 13, 00, 00)
                },
                new Inspection
                {
                    OpensOn = new DateTime(2015, 5, 7, 11, 55, 00),
                    ClosesOn = new DateTime(2015, 5, 7, 13, 00, 00)
                }
            };
            listing.LandDetails = new LandDetails
            {
                Area = new Depth
                {
                    Value = 1.234m,
                    Type = "some type",
                    Side = "some side"
                },
                CrossOver = "some cross over",
                Depths = new List<Depth>
                {
                    new Depth
                    {
                        Value = 1234.11m,
                        Type = "some type 1",
                        Side = "some side 1"
                    },
                    new Depth
                    {
                        Value = 333.44m,
                        Type = "some type 2",
                        Side = "some side 2"
                    }
                },
                Frontage = new Depth
                {
                    Value = 1234.11m,
                    Type = "some type 1",
                    Side = "some side 1"
                }
            };
            listing.Links = new List<string>(new[] {"link 1", "link 2"});
            listing.StatusType = StatusType.Current;
            listing.Title = "some title";
            listing.Videos = new List<Media>
            {
                new Media
                {
                    Url = "http://a.b.c/video1",
                    Order = 1,
                    Tag = "v1"
                },
                new Media
                {
                    Url = "http://a.b.c/video2",
                    Order = 2,
                    Tag = "v2"
                }
            };
        }
        private static void ExtractCommonData(Listing listing, 
            XElement document, 
            string addressDelimeter)
        {
            listing.ShouldNotBe(null);
            document.ShouldNotBe(null);

            listing.UpdatedOn = ParseReaDateTime(document.AttributeValue("modTime"));

            // We have no idea if this was created before this date, but we need to set a date
            // so we'll default it to this.
            listing.CreatedOn = listing.UpdatedOn;

            listing.AgencyId = document.ValueOrDefault("agentID");
            listing.Id = document.ValueOrDefault("uniqueID");
            var status = document.AttributeValueOrDefault("status");
            if (!string.IsNullOrWhiteSpace(status))
            {
                listing.StatusType = StatusTypeHelpers.ToStatusType(status);
            }

            listing.Title = document.ValueOrDefault("headline");
            listing.Description = document.ValueOrDefault("description");

            listing.Address = ExtractAddress(document, addressDelimeter);
            listing.Agents = ExtractAgent(document);
            listing.Inspections = ExtractInspectionTimes(document);
            listing.Images = ExtractImages(document);
            listing.FloorPlans = ExtractFloorPlans(document);
            listing.Videos = ExtractVideos(document);
            listing.Features = ExtractFeatures(document);
            listing.LandDetails = ExtractLandDetails(document);
            listing.Links = ExtractExternalLinks(document);
        }