Ejemplo n.º 1
0
 public IEnumerable <Url> GetUrlsByEmail(string email)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
     {
         return(context.Urls.Where(u => u.User.EmailAddress == email).ToList());
     }
 }
Ejemplo n.º 2
0
 public Url Get(string hash)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
     {
         return(context.Urls.FirstOrDefault(u => u.ShortenedHash.ToLower() == hash.ToLower()));
     }
 }
Ejemplo n.º 3
0
 public void IncrementViews(int urlId)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
     {
         context.ExecuteCommand("UPDATE Urls SET Views = Views + 1 WHERE Id = {0}", urlId);
     }
 }
Ejemplo n.º 4
0
 public URL Get(string shortUrl)
 {
     using (var context = new UrlShortenerDataContext(_connectionstring))
     {
         return(context.URLs.FirstOrDefault(u => u.UrlShort.ToLower() == shortUrl.ToLower()));
     }
 }
Ejemplo n.º 5
0
 public URL GetUrl(string userEmail, string url)
 {
     using (var context = new UrlShortenerDataContext(_connectionstring))
     {
         return(context.URLs.FirstOrDefault(u => u.User.EmailAddress == userEmail && u.UrlOrig == url));
     }
 }
Ejemplo n.º 6
0
 public User GetByEmail(string email)
 {
     using (var context = new UrlShortenerDataContext(_connectionstring))
     {
         return(context.Users.FirstOrDefault(u => u.EmailAddress == email));
     }
 }
Ejemplo n.º 7
0
 public void Add(Url url)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
     {
         context.Urls.InsertOnSubmit(url);
         context.SubmitChanges();
     }
 }
Ejemplo n.º 8
0
        public void AddUser(User user, string password)
        {
            string salt         = PasswordHelper.GenerateSalt();
            string passwordHash = PasswordHelper.HashPassword(password, salt);

            user.PasswordSalt = salt;
            user.PasswordHash = passwordHash;
            using (var context = new UrlShortenerDataContext(_connectionstring))
            {
                context.Users.InsertOnSubmit(user);
                context.SubmitChanges();
            }
        }