예제 #1
0
        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)));
            }
        }
예제 #2
0
        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)));
            }
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
 public IEnumerable <TravelDestinationDto> GetAll()
 {
     return(_allTravelDestinations.Select((destination) => TravelDestinationTransformator.Map(destination)));
 }
예제 #5
0
        public TravelDestinationDto Get(int id)
        {
            var result = _allTravelDestinations.First(x => x.CountryId == id);

            return(TravelDestinationTransformator.Map(result));
        }