Ejemplo n.º 1
0
 public IActionResult ShortenCollection()
 {
     return(View("ShortenCollection", new DocsModel()
     {
         HostName = URLData.GetHostname(Request)
     }));
 }
Ejemplo n.º 2
0
 public IActionResult GetUrlStats()
 {
     return(View("GetUrlStats", new DocsModel()
     {
         HostName = URLData.GetHostname(Request)
     }));
 }
Ejemplo n.º 3
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> UploadURL(URL url)
        {
            if (!ModelState.IsValid)
            {
                var enterURLModel = new EnterURLModel()
                {
                    UrlData = url, HostName = null
                };
                var UserUrls = _urlService.GetUserUrls(_urlContext, HttpContext);

                if (UserUrls.Count() >= 5)
                {
                    UserUrls = UserUrls.Skip(UserUrls.Count() - 5); //Takes last 5 only
                }

                enterURLModel.UserUrls = UserUrls;

                return(View("EnterURL", enterURLModel));
            }

            url.ExternalIP = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();

            await _urlService.AddURL(_urlContext, url, Request);

            var enterUrlModel = new EnterURLModel()
            {
                UrlData = url, UserUrls = _urlService.GetUserUrls(_urlContext, HttpContext), HostName = URLData.GetHostname(Request)
            };

            enterUrlModel.HostName = URLData.GetHostname(Request);

            return(View("DisplayURL", enterUrlModel));
        }
Ejemplo n.º 4
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> ShortenURL(string BaseURL)
        {
            if (!Uri.IsWellFormedUriString(BaseURL, UriKind.Absolute))
            {
                return(StatusCode(400)); //Bad Request - Input must be of type URL
            }

            var urlToAdd = new URL()
            {
                BaseURL = BaseURL
            };

            try //Attempts to add URL to DB
            {
                await _urlService.AddURL(_urlContext, urlToAdd, null);
            }
            catch (Exception postShortURLError)
            {
                Console.WriteLine($"{postShortURLError} at {DateTime.Now}");
                return(StatusCode(500)); //Internal Server Error
            }

            if (!string.IsNullOrEmpty(urlToAdd.ShortenedIdentifier))                                                      //Final check to see if the action is about to return a null value
            {
                var    returnObject = new { shortenedUrl = URLData.GetHostname(Request) + urlToAdd.ShortenedIdentifier }; //Creates object with all of the data needing to be returned
                string returnData   = JsonConvert.SerializeObject(returnObject);                                          //Serializes the object (Second layer to prevent returning a pure object)

                return(Ok(returnData));
            }
            else
            {
                return(StatusCode(500)); //Internal Server Error
            }
        }
Ejemplo n.º 5
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> ShortenCollection([FromBody] IEnumerable <string> UrlList)
        {
            if (UrlList == null || UrlList.Count() == 0)
            {
                return(StatusCode(400));
            }

            List <string> returnList = new List <string>();

            foreach (var baseUrl in UrlList)
            {
                if (Uri.IsWellFormedUriString(baseUrl, UriKind.Absolute))
                {
                    var urlToAdd = new URL {
                        BaseURL = baseUrl
                    };
                    await _urlService.AddURL(_urlContext, urlToAdd, null);

                    returnList.Add(URLData.GetHostname(Request) + urlToAdd.ShortenedIdentifier);
                }
                else
                {
                    returnList.Add("");
                }
            }

            return(Ok(returnList));
        }
Ejemplo n.º 6
0
        public IActionResult UrlList()
        {
            var enterURLModel = new EnterURLModel()
            {
                UrlData = null, UserUrls = _urlService.GetUserUrls(_urlContext, HttpContext), HostName = null
            };

            enterURLModel.HostName = URLData.GetHostname(Request);

            return(View("DisplayURL", enterURLModel));
        }
Ejemplo n.º 7
0
        //GET: .../Index or .../URL/Index (Due to default routing in startup)
        public IActionResult Index()
        {
            var enterUrlModel = new EnterURLModel()
            {
                UrlData = null, HostName = URLData.GetHostname(Request)
            };
            var UserUrls = _urlService.GetUserUrls(_urlContext, HttpContext);

            if (UserUrls.Count() >= 5)
            {
                UserUrls = UserUrls.Skip(UserUrls.Count() - 5); //Takes last 5 only
            }

            enterUrlModel.UserUrls = UserUrls;

            return(View("EnterURL", enterUrlModel));
        }