public void AddUser(User user, string password) { user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password); using (var context = new JokeContext(_connectionString)) { context.Users.Add(user); context.SaveChanges(); } }
public void LikeJoke(Joke joke, int userId, bool liked) { using (var cxt = new JokeContext(_connectionString)) { var ulj = new UserLikedJokes(); ulj.JokeId = joke.Id; ulj.UserId = userId; ulj.Liked = liked; ulj.DateLiked = DateTime.Now; cxt.UserLikedJokes.Add(ulj); if (!cxt.Jokes.Contains(joke)) { cxt.Jokes.Add(joke); } cxt.SaveChanges(); } }