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")); }
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)); }
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); }