public User GetUserById(int id) { using (var ctx = new JokesContext(_connectionString)) { return(ctx.Users.Include(u => u.LikeJokes).FirstOrDefault(u => u.Id == id)); } }
public User GetByEmail(string email) { using (var ctx = new JokesContext(_connectionString)) { return(ctx.Users.Include(u => u.LikeJokes).FirstOrDefault(u => u.Email == email)); } }
public List <UserLikeJoke> GetUserLikeJoke() { using (var ctx = new JokesContext(_connectionString)) { return(ctx.LikeJokes.ToList()); } }
public int GetCountLikesOrDislike(bool like, int?jokeid) { using (var ctx = new JokesContext(_connectionString)) { return(ctx.LikeJokes.Where(lj => lj.JokeId == jokeid).Count(lj => lj.Like == like)); } }
public List <Joke> GetJokes() { using (var ctx = new JokesContext(_connectionString)) { return(ctx.Jokes.Include(u => u.LikeJokes).ToList()); } }
public void AddUserLikeJoke(UserLikeJoke likeJoke) { using (var ctx = new JokesContext(_connectionString)) { ctx.LikeJokes.Add(likeJoke); ctx.SaveChanges(); } }
public void AddUser(User user, string password) { user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password); using (var ctx = new JokesContext(_connectionString)) { ctx.Users.Add(user); ctx.SaveChanges(); } }
public void UpdateLike(int userid, int jokeid, bool like) { using (var context = new JokesContext(_connectionString)) { context.Database.ExecuteSqlCommand("UPDATE LikeJokes SET [Like] = @like WHERE JokeId = @jokeid And UserId = @userid", new SqlParameter("@like", like), new SqlParameter("@jokeid", jokeid), new SqlParameter("@userid", userid)); } }
public void AddJoke(Joke joke) { joke.JokeDataId = (int)joke.Id; joke.Id = null; using (var ctx = new JokesContext(_connectionString)) { ctx.Jokes.Add(joke); ctx.SaveChanges(); } }