public Lodging Create(Lodging lodging) { var touristSpot = TouristSpotRepository.Get(lodging.TouristSpot.Id); if (touristSpot == null) { throw new NotFoundException("TouristSpot"); } if (LodgingRepository.Exists(x => x.Address == lodging.Address && x.IsDeleted == false)) { throw new NotUniqueException("Address"); } lodging.TouristSpot = touristSpot; LodgingRepository.Add(lodging); LodgingRepository.Save(); return(LodgingRepository.GetFirst(x => x.Id == lodging.Id, "TouristSpot,Images")); }
public Booking Create(Booking booking, ICollection <Guest> guests) { var lodging = LodgingRepository.GetFirst(x => x.Id == booking.Lodging.Id && !x.IsDeleted && !x.IsFull); if (lodging == null) { throw new NotFoundException("Lodging"); } booking.Lodging = lodging; booking.TotalPrice = lodging.CalculatePrice((DateTime)booking.CheckIn, (DateTime)booking.CheckOut, guests); BookingRepository.Add(booking); BookingRepository.Save(); return(BookingRepository.GetFirst(x => x.Id == booking.Id)); }