コード例 #1
0
        public IActionResult Show(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var shorturl = _service.GetById(id.Value);

            if (shorturl == null)
            {
                return(NotFound());
            }

            var shortenedUrl = ReBaser.Encode(shorturl.Id);

            return(Accepted(new { shortenUrl = shortenedUrl }));
        }
コード例 #2
0
        public IActionResult Create(string originalUrl)
        {
            Console.WriteLine(originalUrl);
            Regex rgx = new Regex("(http[s]?:\\/\\/)[^\\s([\"<,>]*\\.[^\\s[\\\",><]*");

            if (rgx.IsMatch(originalUrl))
            {
                var shortUrl = new ShortUrl
                {
                    OriginalUrl = originalUrl
                };

                _service.save(shortUrl);
                Console.WriteLine("GotIt");
                return(Created("/ShortUrl/Create", new { id = ReBaser.Encode(shortUrl.Id) }));
            }
            return(Conflict());
        }