public Users GetByEmail(string email) { using (var context = new JokesContext(_connectionString)) { return(context.Users.FirstOrDefault(u => u.Email == email)); } }
public void AddLikeOrDislike(Jokes joke, Users user, bool liked) { UserLikedJokes ulj = GetLike(user.Id, joke.Id); using (var context = new JokesContext(_connectionString)) { var like = new UserLikedJokes { JokeId = joke.Id, UserId = user.Id, Liked = liked, Date = DateTime.Now }; if (ulj == null) { context.UserLikedJokes.Add(like); context.SaveChanges(); } else { context.UserLikedJokes.Attach(like); context.Entry(like).State = EntityState.Modified; context.SaveChanges(); } } }
public UserLikedJokes GetLike(int userId, int jokeId) { using (var context = new JokesContext(_connectionString)) { return(context.UserLikedJokes.FirstOrDefault(u => u.UserId == userId && u.JokeId == jokeId)); } }
public List <Jokes> GetJokes() { using (var context = new JokesContext(_connectionString)) { return(context.Jokes.Include(j => j.UserjokeLikes).ToList()); } }
public bool EmailAvailable(string email) { using (var context = new JokesContext(_connectionString)) { bool isUsed = context.Users.Any(u => u.Email == email); return(isUsed); } }
public void AddUser(Users user, string password) { string hash = BCrypt.Net.BCrypt.HashPassword(password); user.PasswordHash = hash; using (var context = new JokesContext(_connectionString)) { context.Users.Add(user); context.SaveChanges(); } }
public void AddJoke() { using (var context = new JokesContext(_connectionString)) { JokesApi jokesApi = new JokesApi(); Jokes joke = jokesApi.AddJoke(); joke.Id = 0; context.Jokes.Add(joke); context.SaveChanges(); } }