public User GetByEmail(string email)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
 //Account repo
 public List <Bookmark> GetBookmarks()
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         return(context.Bookmarks.ToList());
     }
 }
 public List <Bookmark> BookmarksForUser(string email)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         User user = GetByEmail(email);
         return(context.Bookmarks.Where(u => u.UserId == user.Id).ToList());
     }
 }
 public bool EmailAvailable(string email)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         bool isUsed = context.Users.Any(u => u.Email == email);
         return(isUsed);
     }
 }
 public void DeleteBookmark(Bookmark bookmark)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         context.Bookmarks.Remove(bookmark);
         context.SaveChanges();
     }
 }
 public void UpdateBookmark(Bookmark bookmark)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         context.Bookmarks.Attach(bookmark);
         context.Entry(bookmark).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
        public void AddUser(User user, string password)
        {
            string hash = BCrypt.Net.BCrypt.HashPassword(password);

            user.PasswordHash = hash;
            using (var context = new UserBookmarkContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
 //Bookmark repo
 public List <TopBookmark> GetTopBookMarkUrls()
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         return(context.Bookmarks.GroupBy(b => b.URL)
                .OrderByDescending(b => b.Count()).Take(5)
                .Select(i => new TopBookmark
         {
             Url = i.First().URL,
             Count = i.Count()
         })
                .ToList());
     }
 }