public bool HashExists(string urlHash) { using (var context = new UrlShortenerContext(_connectionString)) { return(context.ShortenedUrls.Any(u => u.UrlHash == urlHash)); } }
public User GetByEmail(string email) { using (var context = new UrlShortenerContext(_connectionString)) { return(context.Users.FirstOrDefault(u => u.Email == email)); } }
public IEnumerable <ShortenedUrl> GetUrlsForUser(string email) { using (var context = new UrlShortenerContext(_connectionString)) { return(context.ShortenedUrls.Where(s => s.User.Email == email).ToList()); } }
public ShortenedUrl GetByHash(string hash) { using (var context = new UrlShortenerContext(_connectionString)) { return(context.ShortenedUrls .FirstOrDefault(u => u.UrlHash == hash)); } }
public void AddView(int urlId) { using (var context = new UrlShortenerContext(_connectionString)) { context.Database.ExecuteSqlCommand("UPDATE ShortenedUrls SET Views = Views + 1 WHERE Id = @id", new SqlParameter("@id", urlId)); } }
public ShortenedUrl GetByOriginalUrl(string originalUrl) { using (var context = new UrlShortenerContext(_connectionString)) { return(context.ShortenedUrls .FirstOrDefault(u => u.OriginalUrl == originalUrl && u.UserId == null)); } }
public void Add(ShortenedUrl url) { using (var context = new UrlShortenerContext(_connectionString)) { context.ShortenedUrls.Add(url); context.SaveChanges(); } }
public void AddUser(User user, string password) { user.PasswordHash = PasswordHelper.HashPassword(password); using (var context = new UrlShortenerContext(_connectionString)) { context.Users.Add(user); context.SaveChanges(); } }
public SqlUrlShortenerRepo(UrlShortenerContext context) { _context = context; }