public IActionResult ShortenUrl(string originalUrl)
        {
            ShortenedUrl url     = null;
            var          urlRepo = new ShortenedUrlsRepository(_connectionString);

            if (User.Identity.IsAuthenticated)
            {
                url = urlRepo.GetByOriginalUrlForUser(User.Identity.Name, originalUrl);
            }
            else
            {
                url = urlRepo.GetByOriginalUrl(originalUrl);
            }

            if (url == null)
            {
                var hash = ShortId.Generate(7);
                while (urlRepo.HashExists(hash))
                {
                    hash = ShortId.Generate(7);
                }
                url = new ShortenedUrl
                {
                    OriginalUrl = originalUrl,
                    UrlHash     = hash
                };
                if (User.Identity.IsAuthenticated)
                {
                    var userRepo = new UserRepository(_connectionString);
                    var user     = userRepo.GetByEmail(User.Identity.Name);
                    url.UserId = user.Id;
                }

                urlRepo.Add(url);
            }

            return(Json(new { shortUrl = GetFullUrl(url.UrlHash) }));
        }