Пример #1
0
        public async Task <IActionResult> Post(string url)
        {
            string shortUrl = await ValidShortUrlGeneratorAsync();

            var createResponse = await Task.Run(() => _urlService.CreateShortUrl(new Entities.Models.Url
            {
                MainUrlAddress = url,
                ShortAddress   = shortUrl
            }));

            if (createResponse == false)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "مشکلی در سمت سرور رخ داده لطفا دوباره تلاش کنید"));
            }
            return(Ok(shortUrl));
        }
Пример #2
0
        public ActionResult <UrlData> UrlShortener([FromBody] JObject param)
        {
            var url = (param != null && param["longurl"] != null) ? param["longurl"].ToString() : "";

            return(_service.CreateShortUrl(url));
        }