public IEnumerable <TravelDestinationDto> GetAll() { using (var sqlConnection = new SqlConnection(_connectionString)) { var command = new SqlCommand(@" SELECT [Id], [Name] FROM [TravelMapAppDb].[dbo].[Countries]"); var allCountries = sqlConnection.Query <TravelDestinationEntity>(command.CommandText, command.ToDynamicParameters()).ToList(); return(allCountries.Select(country => TravelDestinationTransformator.Map(country))); } }
public IEnumerable <TravelDestinationDto> GetTravelsForUser(int userId) { using (var sqlConnection = new SqlConnection(_connectionString)) { var command = new SqlCommand(@" SELECT CountryId, Name FROM VisitedCountries WHERE UserId = @UserId"); command.Parameters.AddWithValue("UserId", userId); var visitedCountries = sqlConnection.Query <TravelDestinationEntity>(command.CommandText, command.ToDynamicParameters()); return(visitedCountries.Select(country => TravelDestinationTransformator.Map(country))); } }
public TravelDestinationDto Get(int id) { using (var sqlConnection = new SqlConnection(_connectionString)) { var command = new SqlCommand(@" SELECT [Id], [Name] FROM [TravelMapAppDb].[dbo].[Countries] WHERE Id = @Id"); command.Parameters.AddWithValue("Id", id); var country = sqlConnection.QueryFirstOrDefault <TravelDestinationEntity>(command.CommandText, command.ToDynamicParameters()); return(TravelDestinationTransformator.Map(country)); } }
public IEnumerable <TravelDestinationDto> GetAll() { return(_allTravelDestinations.Select((destination) => TravelDestinationTransformator.Map(destination))); }
public TravelDestinationDto Get(int id) { var result = _allTravelDestinations.First(x => x.CountryId == id); return(TravelDestinationTransformator.Map(result)); }