Пример #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));
 }