예제 #1
0
        // Bodom: CSRF
        //[ValidateAntiForgeryToken]
        public async Task <ListingResponse> GetListingDetail(int id)
        {
            try
            {
                //if (id < 100000 || id > 1000000) throw new ValidationException(nameof(id));

                var listing = await _listingService.GetListingDetail(id);

                if (listing == null)
                {
                    _logger.LogInformation("Can't find listing with id: {id}", id);
                    throw new ArgumentOutOfRangeException(nameof(id), "Can't find listing");
                }

                return(_mapper.Map <Listing, ListingResponse>(listing,
                                                              opts => opts.BeforeMap((x, y) =>
                {
                    x.ImageList = _imageStorageService.TransformImageUrls(x.ImageList, ImageType.Listing, _device);
                })));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                throw;
            }
        }
예제 #2
0
        public async Task <UserResponse> VerifyEmailtoken(string token)
        {
            try
            {
                var user = await GetUserInfoFromToken(token);

                if (user == null)
                {
                    throw new ArgumentNullException(nameof(token));
                }

                return(_mapper.Map <User, UserResponse>(user
                                                        , opts => opts.BeforeMap((x, y) =>
                {
                    x.TransformImageUrls(_imageStorageService, _device);
                    x.Images = _imageStorageService.TransformImageUrls(x.Images, ImageType.UserProfile, _device);
                    x.HeroImageUrl = _imageStorageService.GetCloudinaryImageUrl(ImageType.UserHeroImage, x.HeroImageUrl, _device);
                })));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                _logger.LogInformation("Can't verify token: {tokenString}", token);
                throw new ValidationException("Token is incorrect");
            }
        }
예제 #3
0
        public static void TransformImageUrls(this User user, IImageStorageService imageStorageService, IDevice device)
        {
            if (user.OperatorListings != null)
            {
                foreach (var listing in user.OperatorListings)
                {
                    listing.ImageUrls = imageStorageService.TransformImageUrls(listing.ImageUrls, ImageType.ListingCard, device);
                }
            }

            if (user.GuestListings != null)
            {
                foreach (var listing in user.GuestListings)
                {
                    listing.ImageUrls = imageStorageService.TransformImageUrls(listing.ImageUrls, ImageType.ListingCard, device);
                }
            }
        }
예제 #4
0
        public async Task <IEnumerable <Article> > GetFeatureArticles(IDevice device)
        {
            var articles = (await _articleRepository.GetFeatureArticles()).ToList();

            foreach (var article in articles)
            {
                article.Title    = WebUtility.HtmlDecode(article.Title);
                article.Content  = WebUtility.HtmlDecode(article.Content);
                article.ImageUrl = _imageStorageService.TransformImageUrls(article.ImageUrl, ImageType.ListingCard, device);
            }

            return(articles);
        }
예제 #5
0
        public async Task <ArticleResponse> GetArticle(int articleId)
        {
            try
            {
                var article = await _articleService.GetArticle(articleId);

                if (article == null)
                {
                    _logger.LogInformation("Can't find article with id: {articleId}", articleId);
                    throw new ArgumentOutOfRangeException(nameof(articleId), "Can't find article");
                }

                return(_mapper.Map <Article, ArticleResponse>(article, opts => opts.BeforeMap((x, y) =>
                {
                    x.ImageUrl = _imageStorageService.TransformImageUrls(x.ImageUrl, ImageType.Article, _device);
                })));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                throw;
            }
        }