예제 #1
0
 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());
 }
예제 #2
0
        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();
        }
예제 #3
0
 public void Delete(int id)
 {
     using var ctx = new SimpleAdsContext(_connectionString);
     ctx.Database.ExecuteSqlInterpolated($"DELETE FROM Ads WHERE Id = {id}");
 }
예제 #4
0
 public int GetUserIdForAd(int adId)
 {
     using var ctx = new SimpleAdsContext(_connectionString);
     return(ctx.Ads.FirstOrDefault(a => a.Id == adId).UserId);
 }
예제 #5
0
 public void AddSimpleAd(SimpleAd ad)
 {
     using var ctx = new SimpleAdsContext(_connectionString);
     ctx.Ads.Add(ad);
     ctx.SaveChanges();
 }
예제 #6
0
 public bool IsEmailAvailable(string email)
 {
     using var ctx = new SimpleAdsContext(_connectionString);
     return(!ctx.Users.Any(u => u.Email == email));
 }
예제 #7
0
 public User GetByEmail(string email)
 {
     using var ctx = new SimpleAdsContext(_connectionString);
     return(ctx.Users.FirstOrDefault(u => u.Email == email));
 }