コード例 #1
0
 public void UpdateBookmark(Bookmark b)
 {
     using var context = new BookmarksDbContext(_connectionString);
     context.Bookmarks.Attach(b);
     context.Entry(b).State = EntityState.Modified;
     context.SaveChanges();
 }
コード例 #2
0
        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();
        }
コード例 #3
0
 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();
     }
 }
コード例 #4
0
 public void DeleteBookmark(int id)
 {
     using var context = new BookmarksDbContext(_connectionString);
     context.Database.ExecuteSqlInterpolated($"DELETE FROM Bookmarks WHERE id={id}");
     context.SaveChanges();
 }