Ejemplo n.º 1
0
 public int GetUserIdForAd(int adId)
 {
     using (var context = new SimpleAdsContext(_connectionString))
     {
         return(context.Ads.FirstOrDefault(a => a.Id == adId).UserId);
     }
 }
Ejemplo n.º 2
0
 public User GetByEmail(string email)
 {
     using (var context = new SimpleAdsContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Ejemplo n.º 3
0
 public bool IsEmailAvailable(string email)
 {
     using (var context = new SimpleAdsContext(_connectionString))
     {
         bool isUsed = context.Users.Any(u => u.Email == email);
         return(!isUsed);
     }
 }
Ejemplo n.º 4
0
 public void Delete(int id)
 {
     using (var context = new SimpleAdsContext(_connectionString))
     {
         context.Database.ExecuteSqlCommand("DELETE FROM Ads WHERE Id = @id",
                                            new SqlParameter("@id", id));
     }
 }
Ejemplo n.º 5
0
 public IEnumerable <SimpleAd> GetAds()
 {
     using (var context = new SimpleAdsContext(_connectionString))
     {
         return(context.Ads.Include(a => a.User)
                .OrderByDescending(a => a.Date).ToList());
     }
 }
Ejemplo n.º 6
0
 public IEnumerable <SimpleAd> GetAdsForUser(int userId)
 {
     using (var context = new SimpleAdsContext(_connectionString))
     {
         return(context.Ads
                .Include(a => a.User)
                .Where(a => a.UserId == userId).ToList());
     }
 }
Ejemplo n.º 7
0
 public void AddSimpleAd(SimpleAd ad)
 {
     ad.Date = DateTime.Now;
     using (var context = new SimpleAdsContext(_connectionString))
     {
         context.Ads.Add(ad);
         context.SaveChanges();
     }
 }
Ejemplo n.º 8
0
        public void AddUser(User user, string password)
        {
            string hash = BCrypt.Net.BCrypt.HashPassword(password);

            user.PasswordHash = hash;
            using (var context = new SimpleAdsContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }