public List <SimpleAd> GetAdsForUser(int userId) { using var ctx = new SimpleAdsContext(_connectionString); return(ctx.Ads.Where(a => a.UserId == userId) .OrderByDescending(a => a.Date) .Include(a => a.User) .ToList()); }
public void AddUser(User user, string password) { string hash = BCrypt.Net.BCrypt.HashPassword(password); using var ctx = new SimpleAdsContext(_connectionString); user.PasswordHash = hash; ctx.Users.Add(user); ctx.SaveChanges(); }
public void Delete(int id) { using var ctx = new SimpleAdsContext(_connectionString); ctx.Database.ExecuteSqlInterpolated($"DELETE FROM Ads WHERE Id = {id}"); }
public int GetUserIdForAd(int adId) { using var ctx = new SimpleAdsContext(_connectionString); return(ctx.Ads.FirstOrDefault(a => a.Id == adId).UserId); }
public void AddSimpleAd(SimpleAd ad) { using var ctx = new SimpleAdsContext(_connectionString); ctx.Ads.Add(ad); ctx.SaveChanges(); }
public bool IsEmailAvailable(string email) { using var ctx = new SimpleAdsContext(_connectionString); return(!ctx.Users.Any(u => u.Email == email)); }
public User GetByEmail(string email) { using var ctx = new SimpleAdsContext(_connectionString); return(ctx.Users.FirstOrDefault(u => u.Email == email)); }