Exemplo n.º 1
0
        public async Task <TripResponse> GetAuthorizedListAsync(FilterTripRequest filterTripRequest, int userId, string currentCulture)
        {
            if (filterTripRequest == null)
            {
                throw new ArgumentNullException(nameof(filterTripRequest));
            }

            var trips = await _tripStorage.GetAuthorizedListAsync(filterTripRequest, userId);

            var pathToUserDirectory = Path.Combine(_appEnvironment.WebRootPath, "Photos", "Users");

            var tripsForListDto = new List <TripForListDto>();

            foreach (var trip in trips)
            {
                var targetPath   = Path.Combine(pathToUserDirectory, $"{trip.User.Login}");
                var targetImages = new List <string>();
                if (Directory.Exists(targetPath))
                {
                    targetImages = Directory.GetFiles(targetPath, "*_icon.jpeg").ToList();
                }
                var tripDto = new TripForListDto
                {
                    Id           = trip.Id,
                    UserName     = trip.User.FirstName,
                    DateFrom     = trip.DateFrom,
                    DateTo       = trip.DateTo,
                    IsCompleted  = trip.IsCompleted,
                    IsDeleted    = trip.IsDeleted,
                    UserLogin    = trip.User.Login,
                    ImageUri     = $"https://www.amver.net/Photos/Countries/{trip.ToCountry.Name}/{trip.ToCountry.Name}_main.png",
                    UserImageUri = targetImages.Any() ? $"https://www.amver.net/Photos/Users/{trip.User.Login}/{Path.GetFileName(targetImages.First())}" : Path.Combine("https://www.amver.net", "images", "userAccountIcon.png")
                };
                switch (currentCulture)
                {
                case Cultures.Ru:
                    tripDto.FromCity    = trip.FromCity.ruRu;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.ruRu;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.ruRu;
                    tripDto.ToCountry   = trip.ToCountry.ruRu;
                    break;

                default:
                    tripDto.FromCity    = trip.FromCity.Name;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.Name;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.Name;
                    tripDto.ToCountry   = trip.ToCountry.Name;
                    break;
                }
                tripsForListDto.Add(tripDto);
            }

            var tripResponse = new TripResponse
            {
                Trips = tripsForListDto,
                Count = tripsForListDto.Count
            };

            return(tripResponse);
        }
Exemplo n.º 2
0
        public async Task <TripResponse> GetListByUserIdAsync(int userId, string currentCulture)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            var trips = await _tripStorage.GetByUserIdAsync(userId);

            var pathToDirectory     = Path.Combine(_appEnvironment.ContentRootPath, "wwwroot", "Photos", "Countries");
            var pathToUserDirectory = Path.Combine(_appEnvironment.WebRootPath, "Photos", "Users");

            var tripsForListDto = new List <TripForListDto>();

            foreach (var trip in trips)
            {
                var tripDto = new TripForListDto
                {
                    Id          = trip.Id,
                    UserName    = trip.User.FirstName,
                    DateFrom    = trip.DateFrom,
                    DateTo      = trip.DateTo,
                    IsCompleted = trip.IsCompleted,
                    IsDeleted   = trip.IsDeleted,
                    UserLogin   = trip.User.Login,
                    ImageUri    = $"https://www.amver.net/Photos/Countries/{trip.ToCountry.Name}/{trip.ToCountry.Name}_main.png"
                };
                switch (currentCulture)
                {
                case Cultures.Ru:
                    tripDto.FromCity    = trip.FromCity.ruRu;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.ruRu;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.ruRu;
                    tripDto.ToCountry   = trip.ToCountry.ruRu;
                    break;

                default:
                    tripDto.FromCity    = trip.FromCity.Name;
                    tripDto.FromCountry = trip.FromCountry == null ? string.Empty : trip.FromCity.Country.Name;
                    tripDto.ToCity      = trip.ToCity == null ? string.Empty : trip.ToCity.Name;
                    tripDto.ToCountry   = trip.ToCountry.Name;
                    break;
                }
                tripsForListDto.Add(tripDto);
            }

            var tripResponse = new TripResponse
            {
                Trips = tripsForListDto,
                Count = tripsForListDto.Count
            };

            return(tripResponse);
        }