Exemplo n.º 1
0
 public List <Bookmark> GetBookmarks(int userId)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         return(ctx.Bookmarks.Where(b => b.UserId == userId).ToList());
     }
 }
Exemplo n.º 2
0
 public User GetByEmail(string email)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         return(ctx.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Exemplo 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();
     }
 }
Exemplo 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();
     }
 }
Exemplo n.º 5
0
 public void AddBookmark(Bookmark bookmark)
 {
     using (var ctx = new BookmarkContext(_connectionString))
     {
         ctx.Bookmarks.Add(bookmark);
         ctx.SaveChanges();
     }
 }
Exemplo 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());
            }
        }
Exemplo 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();
            }
        }