The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Shortener.cs 930B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Teknik.Areas.Shortener.Models;
  7. using Teknik.Helpers;
  8. using Teknik.Models;
  9. namespace Teknik.Areas.Shortener
  10. {
  11. public static class Shortener
  12. {
  13. public static ShortenedUrl ShortenUrl(string url, int length)
  14. {
  15. TeknikEntities db = new TeknikEntities();
  16. // Generate the shortened url
  17. string shortUrl = Utility.RandomString(length);
  18. while (db.ShortenedUrls.Where(s => s.ShortUrl == shortUrl).FirstOrDefault() != null)
  19. {
  20. shortUrl = Utility.RandomString(length);
  21. }
  22. ShortenedUrl newUrl = new ShortenedUrl();
  23. newUrl.OriginalUrl = url;
  24. newUrl.ShortUrl = shortUrl;
  25. newUrl.DateAdded = DateTime.Now;
  26. return newUrl;
  27. }
  28. }
  29. }