コード例 #1
0
        public string ShortUrl(string Url)
        {
            if (Url.Trim() != "")
            {
                string shortUrl = GetRandomUrl();
                while (db.urlShortners.Any(ur => ur.long_url == Url))
                {
                    shortUrl = GetRandomUrl();
                }

                UrlShortner data = new UrlShortner();
                data.id            = 1;
                data.long_url      = Url;
                data.short_url     = shortUrl;
                data.clicked       = 1;
                data.created_by    = "test";
                data.created_date  = DateTime.Now;
                data.modfied_by    = "test";
                data.modified_date = DateTime.Now;
                data.token         = "";
                data.deleted       = false;
                db.urlShortners.Add(data);
                db.SaveChanges();
                return(shortUrl);
            }
            return("");
        }
コード例 #2
0
        public void AddMember(MemberDto memberDto)
        {
            string shortUrl = UrlShortner.ShortenUrl(memberDto.Url);

            Member member = new Member()
            {
                Id         = Guid.NewGuid().ToString(),
                Name       = memberDto.Name,
                WebsiteUrl = memberDto.Url,
                ShortUrl   = shortUrl,
                Headings   = new List <Heading>()
            };
            var content = _webScrappingHelper.GetTextofHeadingTags(memberDto.Url);

            foreach (var item in content)
            {
                Heading heading = new Heading()
                {
                    Content     = item.Content,
                    HeadingType = item.HeadingType,
                    Id          = Guid.NewGuid().ToString(),
                    MemberId    = member.Id
                };

                member.Headings.Add(heading);
            }

            _memberDataProvider.AddMember(member);
        }
コード例 #3
0
        public void IdToShortUrlTest()
        {
            var id          = 12345;
            var urlShortner = new UrlShortner();
            var result      = urlShortner.IdToShortUrl(id);

            Assert.AreEqual("dnh", result);
        }
コード例 #4
0
        public void ShortUrlToIntTest()
        {
            var shortUrl    = "dnh";
            var urlShortner = new UrlShortner();
            var result      = urlShortner.ShortUrlToId(shortUrl);

            Assert.AreEqual(12345, result);
        }
コード例 #5
0
        void OpenUrl(Uri url)
        {
            // shorten URL
            var urlShortner = new UrlShortner(url);

            if (urlShortner.Shorten() && urlShortner.IsShort)
            {
                url = urlShortner.ShortUrl;
            }

            Process.Start(url.AbsoluteUri);
        }