Esempio n. 1
0
 public List <Bookmark> GetBookmarks(int userId)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         return(ctx.Bookmarks.Where(b => b.UserId == userId).ToList());
     }
 }
Esempio n. 2
0
 public User GetByEmail(string email)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         return(ctx.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Esempio n. 3
0
 public void DeleteBookmark(int bookmarkId)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         ctx.Database.ExecuteSqlInterpolated($"DELETE FROM Bookmarks WHERE Id = {bookmarkId}");
         ctx.SaveChanges();
     }
 }
Esempio n. 4
0
 public void UpdateBookmark(string newTitle, int bookmarkId)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         ctx.Database.ExecuteSqlInterpolated($"UPDATE Bookmarks SET Title = {newTitle} WHERE Id = {bookmarkId}");
         ctx.SaveChanges();
     }
 }
Esempio n. 5
0
 public void AddBookmark(Bookmark bookmark)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         ctx.Bookmarks.Add(bookmark);
         ctx.SaveChanges();
     }
 }
Esempio n. 6
0
        public List <TopBookmark> GetTopFive()
        {
            var query = "SELECT TOP 5 Url, Count(*) AS 'Count' FROM Bookmarks GROUP BY Url ORDER BY COUNT(*) DESC";

            using (var ctx = new BookmarkContext(_connectionString))
            {
                return(ctx.TopBookmarks.FromSqlRaw(query).ToList());
            }
        }
Esempio n. 7
0
        public void AddUser(User user, string password)
        {
            user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password);

            using (var ctx = new BookmarkContext(_connectionString))
            {
                ctx.Users.Add(user);
                ctx.SaveChanges();
            }
        }