コード例 #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"));
        }
コード例 #2
0
        public ICollection <ReportBasicInfoModel> Search(ReportModel reportModel)
        {
            var touristSpot = TouristSpotRepository.GetFirst(spot => spot.Id == reportModel.TouristSpot);

            if (touristSpot == null)
            {
                throw new NotFoundException("TouristSpot");
            }

            if (!TouristSpotRepository.HasAnyBooking(touristSpot.Id))
            {
                var error = new Notification();
                error.AddError("TouristSpot", "Has no bookings");
                throw new EntityNotValidException(error);
            }

            return(LodgingRepository.Search(reportModel));
        }
コード例 #3
0
        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);
        }