public ActionResult <LinkBundles> UpdatePath(UpdatePathObject data)
        {
            LinkBundles linkBundles = _services.UpdatePath(data.linkBundle.FullURL, data.newPath);

            if (linkBundles == null)
            {
                return(NotFound());
            }
            return(linkBundles);
        }
        public ActionResult <LinkBundles> AddLink(LinkBundles bundle)
        {
            var linkBundles = _services.SubmitURL(bundle.FullURL);

            if (linkBundles == null)
            {
                return(NotFound());
            }
            return(linkBundles);
        }
Exemplo n.º 3
0
        // uri class **
        public LinkBundles SubmitURL(Uri url)
        {
            // Use uri class for validation of url, etc.
            // If Submitted URL doesn't already exist, add to dictionary
            LinkBundles existingBundle = _linkBundles.Values.FirstOrDefault(bundle => bundle.FullURL == url);

            if (existingBundle != null)
            {
                return(existingBundle);
            }
            else
            {
                return(AddURL(url));
            }
        }
Exemplo n.º 4
0
        private LinkBundles AddURL(Uri url)
        {
            // Uses a GUID to store instance Id and provide the unique Id for short url
            Guid        guid          = Guid.NewGuid();
            LinkBundles newLinkBundle = new LinkBundles
            {
                Id        = guid,
                FullURL   = url,
                ShortURL  = new Uri("https://localhost:5001/l/" + guid.ToString().Substring(0, 8)),
                CreatedAt = DateTime.Now
            };

            _linkBundles.Add(newLinkBundle.Id.ToString(), newLinkBundle);

            return(newLinkBundle);
        }