The next generation of the Teknik Services. Written in ASP.NET.
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.

34 lines
942 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teknik.Areas.Shortener.Models;
using Teknik.Utilities;
using Teknik.Models;
namespace Teknik.Areas.Shortener
public static class Shortener
public static ShortenedUrl ShortenUrl(string url, int length)
TeknikEntities db = new TeknikEntities();
// Generate the shortened url
string shortUrl = StringHelper.RandomString(length);
while (db.ShortenedUrls.Where(s => s.ShortUrl == shortUrl).FirstOrDefault() != null)
shortUrl = StringHelper.RandomString(length);
ShortenedUrl newUrl = new ShortenedUrl();
newUrl.OriginalUrl = url;
newUrl.ShortUrl = shortUrl;
newUrl.DateAdded = DateTime.Now;
return newUrl;