public List <Bookmark> GetMyBookmarks() { var user = GetCurrentUser(); var bookmarksRepo = new BookmarksRepository(_connectionString); return(bookmarksRepo.GetForUser(user.Id)); }
public List <Bookmark> GetUserBookmarks() { var repo = new BookmarksRepository(_connectionString); int userId = repo.GetByEmail(User.Identity.Name).Id; return(repo.GetUserBookmarks(userId)); }
public void AddBookmark(Bookmark b) { var repo = new BookmarksRepository(_connectionString); b.UserId = repo.GetByEmail(User.Identity.Name).Id; repo.AddBookmark(b); }
public List <TopBookmark> GetTopFiveBookmarks() { var bookmarksRepo = new BookmarksRepository(_connectionString); return(bookmarksRepo.GetTopBookmarkUrls()); //return bookmarksRepo.GetTopBookmarkUrls_TheLongWay(); //return bookmarksRepo.GetTopBookmarkUrls_DbQueryWay(); }
public void Add(Bookmark bookmark) { var user = GetCurrentUser(); bookmark.UserId = user.Id; var bookmarksRepo = new BookmarksRepository(_connectionString); bookmarksRepo.Add(bookmark); }
public User GetCurrentUser() { if (!User.Identity.IsAuthenticated) { return(null); } var repo = new BookmarksRepository(_connectionString); return(repo.GetByEmail(User.Identity.Name)); }
public void Delete(DeleteViewModel viewModel) { var user = GetCurrentUser(); var bookmarksRepo = new BookmarksRepository(_connectionString); if (!bookmarksRepo.UserOwnsBookmark(user.Id, viewModel.BookmarkId)) { return; } bookmarksRepo.DeleteBookmark(viewModel.BookmarkId); }
private static void AddThreeRandomUrls(int userId) { Console.WriteLine($"Adding urls for {userId}"); var three = urls.OrderBy(g => Guid.NewGuid()).Take(3).ToList(); var bookmarksRepo = new BookmarksRepository(_connectionString); foreach (var url in three) { Console.WriteLine($"\tAdded url {url.Url}"); bookmarksRepo.Add(new Bookmark { Title = url.Title, Url = url.Url, UserId = userId }); } }
public User Login(LoginViewModel vm) { var repo = new BookmarksRepository(_connectionString); var user = repo.Login(vm.Email, vm.Password); if (user == null) { return(null); } var claims = new List <Claim> { new Claim("user", vm.Email) }; HttpContext.SignInAsync(new ClaimsPrincipal( new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait(); return(user); }
public BookmarksController(IConfiguration configuration) { repo = new BookmarksRepository(configuration); }
public void Signup(SignupViewModel vm) { var repo = new BookmarksRepository(_connectionString); repo.AddUser(vm, vm.Password); }
public List <PopularUrls> GetTop5Urls() { var repo = new BookmarksRepository(_connectionString); return(repo.GetTop5Urls()); }
public void UpdateBookmark(Bookmark b) { var repo = new BookmarksRepository(_connectionString); repo.UpdateBookmark(b); }
public void DeleteBookmark(DeleteBookmarkViewModel vm) { var repo = new BookmarksRepository(_connectionString); repo.DeleteBookmark(vm.BookmarkId); }