示例#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();
            }
        }