public User GetUsersBookmarks(int userId)
 {
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         return(cxt.Users.Include(u => u.Bookmarks).FirstOrDefault(u => u.Id == userId));
     }
 }
Exemple #2
0
 public User GetUserByEmail(string email)
 {
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         return(cxt.Users.FirstOrDefault(u => u.Email == email));
     }
 }
 public void AddBookmark(Bookmark bookmark)
 {
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         cxt.Bookmarks.Add(bookmark);
         cxt.SaveChanges();
     }
 }
 public void DeleteBookmark(int bookmarkId)
 {
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         cxt.Database.ExecuteSqlCommand(
             "DELETE FROM Bookmarks WHERE Id = @id",
             new SqlParameter("@id", bookmarkId));
     }
 }
 public void EditBookmark(Bookmark bookmark)
 {
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         cxt.Bookmarks.Attach(bookmark);
         cxt.Entry(bookmark).State = EntityState.Modified;
         cxt.SaveChanges();
     }
 }
Exemple #6
0
 public void AddUser(User user, string password)
 {
     user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password);
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         cxt.Users.Add(user);
         cxt.SaveChanges();
     }
 }
 public List <Top5Bookmarks> GetTop5Bookmarks()
 {
     using (var cxt = new UserBookmarkContext(_connectionString))
     {
         foreach (Bookmark bookmark in cxt.Bookmarks)
         {
             var inList = IsInList(result, bookmark.Title);
             if (!inList)
             {
                 result.Add(new Top5Bookmarks
                 {
                     Amount   = cxt.Bookmarks.Count(b => b.Title == bookmark.Title),
                     Bookmark = bookmark
                 });
             }
         }
         return(result.OrderByDescending(r => r.Amount).Take(5).ToList());
     }
 }