예제 #1
0
 public bool DoesShortenedUrlExist(string url)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Urls.Any(u => u.UrlShortened == url));
     }
 }
예제 #2
0
 public bool DoesOriginalUrlExist(string url)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Urls.Any(u => u.UrlOriginal == url));
     }
 }
예제 #3
0
 public Url GetOriginalUrl(string url)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Urls.FirstOrDefault(u => u.UrlShortened == url));
     }
 }
예제 #4
0
 public IEnumerable <Url> GetUrls(int userId)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Urls.Where(u => u.UserId == userId).ToList());
     }
 }
예제 #5
0
 public User GetByEmail(string email)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
예제 #6
0
 public void AddUrl(Url url)
 {
     using (var context = new UrlContext(_connectionString))
     {
         context.Urls.Add(url);
         context.SaveChanges();
     }
 }
예제 #7
0
 public void UpdateUrl(int id)
 {
     using (var context = new UrlContext(_connectionString))
     {
         context.Database.ExecuteSqlCommand(
             "UPDATE Urls SET Views = Views + 1 WHERE Id = @id",
             new SqlParameter("@id", id)
             );
     }
 }
예제 #8
0
        public void AddUser(User user, string password)
        {
            user.Password = PasswordEncryption.HashPassword(password);

            using (var context = new UrlContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }