public bool DoesShortenedUrlExist(string url) { using (var context = new UrlContext(_connectionString)) { return(context.Urls.Any(u => u.UrlShortened == url)); } }
public bool DoesOriginalUrlExist(string url) { using (var context = new UrlContext(_connectionString)) { return(context.Urls.Any(u => u.UrlOriginal == url)); } }
public Url GetOriginalUrl(string url) { using (var context = new UrlContext(_connectionString)) { return(context.Urls.FirstOrDefault(u => u.UrlShortened == url)); } }
public IEnumerable <Url> GetUrls(int userId) { using (var context = new UrlContext(_connectionString)) { return(context.Urls.Where(u => u.UserId == userId).ToList()); } }
public User GetByEmail(string email) { using (var context = new UrlContext(_connectionString)) { return(context.Users.FirstOrDefault(u => u.Email == email)); } }
public void AddUrl(Url url) { using (var context = new UrlContext(_connectionString)) { context.Urls.Add(url); context.SaveChanges(); } }
public void UpdateUrl(int id) { using (var context = new UrlContext(_connectionString)) { context.Database.ExecuteSqlCommand( "UPDATE Urls SET Views = Views + 1 WHERE Id = @id", new SqlParameter("@id", id) ); } }
public void AddUser(User user, string password) { user.Password = PasswordEncryption.HashPassword(password); using (var context = new UrlContext(_connectionString)) { context.Users.Add(user); context.SaveChanges(); } }