public void UpdateBookmark(Bookmark b) { using var context = new BookmarksDbContext(_connectionString); context.Bookmarks.Attach(b); context.Entry(b).State = EntityState.Modified; context.SaveChanges(); }
public void AddUser(User user, string password) { string hash = BCrypt.Net.BCrypt.HashPassword(password); using var ctx = new BookmarksDbContext(_connectionString); user.PasswordHash = hash; ctx.Users.Add(user); ctx.SaveChanges(); }
public void AddBookmark(Bookmark b) { using var context = new BookmarksDbContext(_connectionString); if (!context.Bookmarks.Where(bm => bm.UserId == b.UserId).Any(bm => bm.Url == b.Url)) { context.Bookmarks.Add(b); context.SaveChanges(); } }
public void DeleteBookmark(int id) { using var context = new BookmarksDbContext(_connectionString); context.Database.ExecuteSqlInterpolated($"DELETE FROM Bookmarks WHERE id={id}"); context.SaveChanges(); }