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(""); }
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); }
public void IdToShortUrlTest() { var id = 12345; var urlShortner = new UrlShortner(); var result = urlShortner.IdToShortUrl(id); Assert.AreEqual("dnh", result); }
public void ShortUrlToIntTest() { var shortUrl = "dnh"; var urlShortner = new UrlShortner(); var result = urlShortner.ShortUrlToId(shortUrl); Assert.AreEqual(12345, result); }
void OpenUrl(Uri url) { // shorten URL var urlShortner = new UrlShortner(url); if (urlShortner.Shorten() && urlShortner.IsShort) { url = urlShortner.ShortUrl; } Process.Start(url.AbsoluteUri); }