예제 #1
0
        public TouristSpot Create(TouristSpot touristSpot)
        {
            var region = RegionRepository.Get(touristSpot.RegionId);

            if (region == null)
            {
                throw new NotFoundException("Region");
            }

            if (touristSpot.TouristSpotCategories
                .Any(touristSpotCategory => CategoryRepository.Get(touristSpotCategory.CategoryId) == null))
            {
                throw new NotFoundException("Category");
            }

            TouristSpotRepository.Add(touristSpot);
            TouristSpotRepository.Save();

            return(TouristSpotRepository.GetFirst(x => x.Id == touristSpot.Id, "TouristSpotCategories.Category"));
        }
        private TouristSpot TouristSpotFromParsedModel(LodgingParsed lodgingParsed)
        {
            var touristSpot = TouristSpotRepository.GetFirst(x => x.Name == lodgingParsed.TouristSpot.Name);

            if (touristSpot == null)
            {
                touristSpot = new TouristSpot
                {
                    Name        = lodgingParsed.TouristSpot.Name,
                    Description = lodgingParsed.Description,
                    RegionId    = lodgingParsed.TouristSpot.RegionId
                };

                if (!touristSpot.IsValid("Image"))
                {
                    throw new EntityNotValidException(touristSpot.Validate("Image"));
                }

                TouristSpotRepository.Add(touristSpot);
                TouristSpotRepository.Save();
            }

            return(touristSpot);
        }