The next generation of the Teknik Services. Written in ASP.NET. Fork for blog tags.
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 894B

12345678910111213141516171819202122232425262728293031
  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.Utilities;
  8. using Teknik.Models;
  9. namespace Teknik.Areas.Shortener
  10. {
  11. public static class Shortener
  12. {
  13. public static ShortenedUrl ShortenUrl(TeknikEntities db, string url, int length)
  14. {
  15. // Generate the shortened url
  16. string shortUrl = StringHelper.RandomString(length);
  17. while (db.ShortenedUrls.Where(s => s.ShortUrl == shortUrl).FirstOrDefault() != null)
  18. {
  19. shortUrl = StringHelper.RandomString(length);
  20. }
  21. ShortenedUrl newUrl = new ShortenedUrl();
  22. newUrl.OriginalUrl = url;
  23. newUrl.ShortUrl = shortUrl;
  24. newUrl.DateAdded = DateTime.Now;
  25. return newUrl;
  26. }
  27. }
  28. }