public async Task <string> HandleAsync(string shortUrl) { var doc = await _shortenerService.GetByShortUrl(shortUrl); if (doc != null) { _shortenerService.IncrementCounter(shortUrl); } return(doc?.LongUrl); }
public async Task <ShortenResponseContract> HandleAsync(ShortenRequestContract contract, string sessionId) { var shortUrl = ShortenUrlHelper.GetRandomString(); while (await _shortenerService.GetByShortUrl(shortUrl) != null) { shortUrl = ShortenUrlHelper.GetRandomString(); } var doc = new UrlDocument { Created = DateTime.UtcNow, SessionId = sessionId, LongUrl = contract.LongUrl, ShortUrl = shortUrl, }; _shortenerService.SaveNewUrl(doc); return(new ShortenResponseContract { ShortUrl = shortUrl, }); }