Exemplo n.º 1
0
 public User GetByEmail(string email)
 {
     using (var context = new URLShortenerDataContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
 public IEnumerable <URL> GetByUser(int userId)
 {
     using (var context = new URLShortenerDataContext(_connectionString))
     {
         return(context.URLs.Where(u => u.UserId == userId).ToList());
     }
 }
 public URL GetByShortURL(string shortURL)
 {
     using (var context = new URLShortenerDataContext(_connectionString))
     {
         return(context.URLs.FirstOrDefault(u => u.ShortURL == shortURL));
     }
 }
 public void UpdateViewsCount(int id)
 {
     using (var context = new URLShortenerDataContext(_connectionString))
     {
         context.ExecuteCommand("UPDATE URLs SET Views = Views + 1 WHERE Id = {0}", id);
     }
 }
 public void AddURL(URL u)
 {
     using (var context = new URLShortenerDataContext(_connectionString))
     {
         context.URLs.InsertOnSubmit(u);
         context.SubmitChanges();
     }
 }
Exemplo n.º 6
0
        public void AddUser(User user, string password)
        {
            string passwordSalt = PasswordHelper.GenerateSalt();
            string passwordHash = PasswordHelper.HashPassword(password, passwordSalt);

            user.PasswordSalt = passwordSalt;
            user.PasswordHash = passwordHash;
            using (var context = new URLShortenerDataContext(_connectionString))
            {
                context.Users.InsertOnSubmit(user);
                context.SubmitChanges();
            }
        }