Пример #1
0
 public void AddUrl(Url url)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
     {
         context.Urls.InsertOnSubmit(url);
         context.SubmitChanges();
     }
 }
Пример #2
0
 public void AddUser(User user, string password)
 {
     user.PasswordSalt = PasswordHelper.GenerateSalt();
     user.PasswordHash = PasswordHelper.HashPassword(password, user.PasswordSalt);
     using (var context = new UrlShortenerDataContext(_connectionString))
     {
         context.Users.InsertOnSubmit(user);
         context.SubmitChanges();
     }
 }
Пример #3
0
 public void IncremementViews(int id)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
         context.ExecuteCommand("Update Urls Set views = Views + 1 WHERE Id = {0}", id);
 }
Пример #4
0
 public Url Check(string Url, string email)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
         return(context.Urls.FirstOrDefault(u => u.OriginalUrl == Url && u.User.Email == email));
 }
Пример #5
0
 public IEnumerable <Url> GetUrls(int id)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
         return(context.Urls.Where(u => u.UserId == id).ToList()); ;
 }
Пример #6
0
 public Url GetOriginal(string shortened)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
         return(context.Urls.FirstOrDefault(u => u.ShortenedUrl == shortened));
 }
Пример #7
0
 public User GetByEmail(string email)
 {
     using (var context = new UrlShortenerDataContext(_connectionString))
         return(context.Users.FirstOrDefault(e => e.Email == email));
 }