public async Task <ApplicationResponse <ShortUrlResponseDto> > Get(string shortUrl) { var encodeUrl = WebUtility.UrlEncode(shortUrl); var entityShortUrl = await _shortUrlRepository.GetAsync(url => url.ShortUrlValue.Equals(encodeUrl)); if (entityShortUrl.ExpireDate <= DateTime.Now) { return(new ApplicationResponse <ShortUrlResponseDto>(ResponseState.Error, "Url is expired")); } var result = UrlShortMapper.Map(entityShortUrl); return(new ApplicationResponse <ShortUrlResponseDto>(result)); }
public async Task <ApplicationResponse <ShortUrlResponseDto> > Add(ShortUrlRequestDto shortUrlRequestDto) { var currentUser = await GetCurrentUser(); var mongoShortUrlEntity = new ShortUrl { Id = ObjectId.GenerateNewId().ToString(), LongUrlValue = WebUtility.UrlEncode(shortUrlRequestDto.LongURL), ShortUrlValue = await GenerateShortUrl(), User = currentUser, ExpireDate = shortUrlRequestDto.ExpireDate }; await _shortUrlRepository.AddAsync(mongoShortUrlEntity); var mapObject = UrlShortMapper.Map(mongoShortUrlEntity); return(new ApplicationResponse <ShortUrlResponseDto>(mapObject)); }