コード例 #1
0
 public User GetByEmail(string email)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
コード例 #2
0
 //Account repo
 public List <Bookmark> GetBookmarks()
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         return(context.Bookmarks.ToList());
     }
 }
コード例 #3
0
 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());
     }
 }
コード例 #4
0
 public bool EmailAvailable(string email)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         bool isUsed = context.Users.Any(u => u.Email == email);
         return(isUsed);
     }
 }
コード例 #5
0
 public void DeleteBookmark(Bookmark bookmark)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         context.Bookmarks.Remove(bookmark);
         context.SaveChanges();
     }
 }
コード例 #6
0
 public void UpdateBookmark(Bookmark bookmark)
 {
     using (var context = new UserBookmarkContext(_connectionString))
     {
         context.Bookmarks.Attach(bookmark);
         context.Entry(bookmark).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
 //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());
     }
 }