Example #1
0
        public List <Bookmark> GetBookmarks()
        {
            var user = GetCurrentUser();
            var repo = new BookmarkRepository(_connectionString);

            return(repo.GetBookmarks(user.Id));
        }
Example #2
0
        public static void TestDb()
        {
            var bms = new BookmarkRepository(new DatabaseFactory()).GetAll().First();

            bms.Name.ToConsole();
            bms.URL.ToConsole();
        }
        // GET: /<controller>/
        public IActionResult Index()
        {
            var repo      = new BookmarkRepository("peter");
            var Bookmarks = repo.GetBookmarks("AAA");

            return(View(Bookmarks));
        }
Example #4
0
        public void GetBookmarks()
        {
            BookmarkRepository br = new BookmarkRepository();
            List<Bookmark> bl = br.getBookmarks();

            Assert.AreNotEqual(null, bl);
        }
Example #5
0
        public Topics(
            ApplicationDbContext applicationDbContext,
            UserContext userContext,
            BoardRepository boardRepository,
            BookmarkRepository bookmarkRepository,
            MessageRepository messageRepository,
            RoleRepository roleRepository,
            SmileyRepository smileyRepository,
            TopicRepository topicRepository,
            IForumViewResult forumViewResult,
            IActionContextAccessor actionContextAccessor,
            IUrlHelperFactory urlHelperFactory
            )
        {
            DbContext   = applicationDbContext;
            UserContext = userContext;

            BoardRepository    = boardRepository;
            BookmarkRepository = bookmarkRepository;
            MessageRepository  = messageRepository;
            RoleRepository     = roleRepository;
            SmileyRepository   = smileyRepository;
            TopicRepository    = topicRepository;

            ForumViewResult = forumViewResult;
            UrlHelper       = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext);
        }
        public IActionResult Index(ImportBookmarks importBookmarks)
        {
            if (ModelState.IsValid)
            {
                var buckeName = importBookmarks.Bucket;

                var          streamToImprove = importBookmarks.NetscapeBookmarkFile.OpenReadStream();
                MemoryStream improvedStream  = ImproveDocumentStructure(streamToImprove);

                Dictionary <string, List <Link> > bookmarksDictonary = ReadBookmarksIntoDictonary(improvedStream);

                var sections = new List <Section>();


                foreach (var sectionGroup in bookmarksDictonary.GroupBy(kp => kp.Key))
                {
                    sections.Add(new Section(sectionGroup.Key, sectionGroup.First().Value));
                }

                var bookmarks = new Bookmarks(buckeName, sections);


                var repo = new BookmarkRepository("peter");

                repo.AddBookmarks(bookmarks);

                //string linkJson = sections.ToJson();
            }


            //TODO: add success message - ViewBag.
            return(View());
        }
Example #7
0
        public void Editbookmark(Bookmark bookmark)
        {
            var repo  = new BookmarkRepository(_connectionString);
            var repo2 = new UserRepository(_connectionString);
            var user  = repo2.GetUserByEmail(User.Identity.Name);

            bookmark.UserId = user.Id;
            repo.EditBookmark(bookmark);
        }
Example #8
0
        public BookmarksPresenter(BookmarksView view, BookmarkRepository repository)
        {
            ContentView = view;
            ContentView.SetCommand(
                new RelayCommand(ReadBookmark),
                new RelayCommand(DownloadBookmark));

            Repository = repository;
        }
Example #9
0
        public List <Bookmark> GetUsersBookmarks()
        {
            var repo   = new BookmarkRepository(_connectionString);
            var repo2  = new UserRepository(_connectionString);
            var user   = repo2.GetUserByEmail(User.Identity.Name);
            var result = repo.GetUsersBookmarks(user.Id);

            return(result.Bookmarks);
        }
Example #10
0
        public void AddBookmark(Bookmark bm)
        {
            var user = GetCurrentUser();

            bm.UserId = user.Id;
            var repo = new BookmarkRepository(_connectionString);

            repo.AddBookmark(bm);
        }
Example #11
0
        public async Task <IActionResult> Bookmarks()
        {
            var messageIds    = (await BookmarkRepository.Records()).Select(r => r.MessageId).ToList();
            var topicPreviews = await TopicRepository.GetPreviews(messageIds);

            var viewModel = new PageModels.TopicBookmarksPage {
                Topics = topicPreviews
            };

            return(await ForumViewResult.ViewResult(this, viewModel));
        }
Example #12
0
 /// <summary>
 /// 删除书签
 /// </summary>
 public static async Task <int> Delete(Bookmark bookmark)
 {
     if (bookmark == null)
     {
         throw new ArgumentNullException(nameof(bookmark));
     }
     using (DbHelper db = new DbHelper())
     {
         return(await BookmarkRepository.Delete(db, bookmark));
     }
 }
Example #13
0
        public void Cleanup()
        {
            TestEventList.Clear();
            EventRepository    event_repo    = new EventRepository(true);
            UserRepository     user_repo     = new UserRepository(true);
            BookmarkRepository bookmark_repo = new BookmarkRepository(true);

            bookmark_repo.ResetBookmarks();
            event_repo.ResetEvents();
            user_repo.ResetUsers();
        }
Example #14
0
        public void TestAddBookmark()
        {
            // Arrange
            BookmarkRepository repo = _bookmarkRepo;

            // Act
            string result = repo.AddNewBookmark(events[0]);

            // Assert
            Assert.IsTrue(result.Contains("Successfully"));
        }
        public UserDataService()
        {
            ImdbContext context = new ImdbContext();

            _users           = new UserRepository(context);
            _bookmarks       = new BookmarkRepository(context);
            _comments        = new CommentsRepository(context);
            _searchHistory   = new SearchHistoryRepository(context);
            _specialRoles    = new SpecialRolesRepository(context);
            _userRatings     = new UserRatingRepository(context);
            _flaggedComments = new FlaggedCommentsRepository(context);
        }
Example #16
0
        /// <summary>
        /// 修改书签
        /// </summary>
        public static async Task <BookmarkView> Update(Bookmark bookmark)
        {
            if (bookmark == null)
            {
                throw new ArgumentNullException(nameof(bookmark));
            }
            using (DbHelper db = new DbHelper())
            {
                await BookmarkRepository.Update(db, bookmark);

                return(await BookmarkViewRepository.GetById(db, bookmark.Id));
            }
        }
Example #17
0
        public TitleDataService()
        {
            var context = new ImdbContext();

            _castInfo        = new CastInfoRepository(context);
            _titles          = new TitleRepository(context);
            _casts           = new CastsRepository(context);
            _genre           = new GenreRepository(context);
            _format          = new FormatRepository(context);
            _userRating      = new UserRatingRepository(context);
            _titleFormat     = new TitleFormatRepository(context);
            _titleGenre      = new TitleGenreRepository(context);
            _titleAlias      = new TitleAliasRepository(context);
            _titleInfo       = new TitleInfoRepository(context);
            _episodes        = new GenericRepository <Episodes>(context);
            _comments        = new CommentsRepository(context);
            _bookmarks       = new BookmarkRepository(context);
            _flaggedComments = new FlaggedCommentsRepository(context);
        }
Example #18
0
        public Topics(
            ApplicationDbContext applicationDbContext,
            UserContext userContext,
            BoardRepository boardRepository,
            BookmarkRepository bookmarkRepository,
            MessageRepository messageRepository,
            TopicRepository topicRepository,
            IHubContext <ForumHub> forumHub
            )
        {
            DbContext   = applicationDbContext;
            UserContext = userContext;

            BoardRepository    = boardRepository;
            BookmarkRepository = bookmarkRepository;
            MessageRepository  = messageRepository;
            TopicRepository    = topicRepository;

            ForumHub = forumHub;
        }
Example #19
0
        public void ReScanBookmarkThumbnails()
        {
            var repo      = new BookmarkRepository("peter");
            var bookmarks = repo.GetBookmarks("AAA");

            var thumbNailService = new ThumbnailExtractor();

            int count = 0;

            foreach (var section in bookmarks.Sections)
            {
                foreach (var link in section.links)
                {
                    try
                    {
                        if (String.IsNullOrEmpty(link.imgUrl) && count < 200)
                        {
                            count++;

                            var thumbnailLink = thumbNailService.GetSiteIconUrl(link.linkUrl);
                            if (!String.IsNullOrEmpty(thumbnailLink))
                            {
                                if (!thumbnailLink.StartsWith("http"))
                                {
                                    var linkUrl = new Uri(link.linkUrl);
                                    thumbnailLink = linkUrl.OriginalString.Replace(linkUrl.AbsolutePath, "") + thumbnailLink;
                                }

                                link.imgUrl = thumbnailLink;
                            }
                        }
                    }
                    catch { }
                }
            }


            repo.UpdateBookmarks(bookmarks);
        }
Example #20
0
        public Topics(
            ApplicationDbContext applicationDbContext,
            UserContext userContext,
            BoardRepository boardRepository,
            BookmarkRepository bookmarkRepository,
            MessageRepository messageRepository,
            SmileyRepository smileyRepository,
            TopicRepository topicRepository,
            IHubContext <ForumHub> forumHub,
            ForumViewResult forumViewResult
            )
        {
            DbContext   = applicationDbContext;
            CurrentUser = userContext;

            BoardRepository    = boardRepository;
            BookmarkRepository = bookmarkRepository;
            MessageRepository  = messageRepository;
            SmileyRepository   = smileyRepository;
            TopicRepository    = topicRepository;

            ForumHub        = forumHub;
            ForumViewResult = forumViewResult;
        }
Example #21
0
        public void TestGetBookmarkedEvents()
        {
            // Arrange
            BookmarkRepository repo      = _bookmarkRepo;
            List <EventRecord> expected1 = events;
            List <EventRecord> expected2 = new List <EventRecord>();

            // Act
            _loginRepo.IsUserLoginValid("TestUser", "TestPass");
            List <EventRecord> result1 = repo.GetAllBookmarkedEvents();

            _loginRepo.IsUserLoginValid("User2", "Pass2");
            List <EventRecord> result2 = repo.GetAllBookmarkedEvents();

            // Assert
            Assert.AreEqual(expected1.Count, result1.Count);
            Assert.AreEqual(expected2.Count, result2.Count);
            for (int i = 0; i < expected1.Count; i++)
            {
                Assert.AreEqual(expected1[i].ListingId, result1[i].ListingId);
                Assert.AreEqual(expected1[i].Title, result1[i].Title);
                Assert.AreEqual(expected1[i].Description, result1[i].Description);
            }
        }
 public BookmarksController()
 {
     //Todo: Use DI container for resolving dependencies :)
     _bookmarkRepository = new BookmarkRepository(new RavenSessionFactory());
     _bookmarkService    = new BookmarkService(_bookmarkRepository);
 }
Example #23
0
        public void Initialize()
        {
            _eventRepo    = new EventRepository(true);
            _userRepo     = new UserRepository(true);
            _bookmarkRepo = new BookmarkRepository(true);
            _loginRepo    = new LoginRepository(true);

            events = new List <EventRecord>();
            users  = new List <UserRecord>();
            users.Add(new UserRecord()
            {
                UserName  = "******",
                Password  = "******",
                FirstName = "John",
                LastName  = "Smith",
                JoinDate  = DateTime.Now,
                IsAdmin   = false,
                UserId    = 1
            });
            users.Add(new UserRecord()
            {
                UserName  = "******",
                Password  = "******",
                FirstName = "Barrack",
                LastName  = "Obama",
                JoinDate  = DateTime.Now,
                IsAdmin   = true,
                UserId    = 2
            });

            events.Add(new EventRecord()
            {
                ListingId   = 1,
                Title       = "TestEvent",
                Description = "TestDescription",
                StartTime   = new DateTime(2020, 4, 1, 12, 0, 0),
                EndTime     = new DateTime(2020, 4, 1, 14, 20, 0),
                LocX        = 35.3,
                LocY        = -120.7,
                UserId      = 1
            });
            events.Add(new EventRecord()
            {
                ListingId   = 2,
                Title       = "SecondEvent",
                Description = "This event starts at 4am lol",
                StartTime   = new DateTime(2020, 3, 27, 4, 0, 0),
                EndTime     = new DateTime(2020, 3, 27, 7, 30, 0),
                LocX        = 35.7,
                LocY        = -121,
                UserId      = 1
            });
            _userRepo.ResetAutoIncrement();
            _eventRepo.ResetAutoIncrement();
            _bookmarkRepo.ResetAutoIncrement();

            foreach (UserRecord record in users)
            {
                _userRepo.PostNewUser(record);
            }
            foreach (EventRecord record in events)
            {
                _loginRepo.IsUserLoginValid("TestUser", "TestPass");
                _eventRepo.PostNewEvent(record);
                _bookmarkRepo.AddNewBookmark(record);
            }
        }
Example #24
0
        public void UpdateBookmark(UpdateBookmarkViewModel vm)
        {
            var repo = new BookmarkRepository(_connectionString);

            repo.UpdateBookmark(vm.NewTitle, vm.BookmarkId);
        }
Example #25
0
        public List <TopBookmark> GetTopFive()
        {
            var repo = new BookmarkRepository(_connectionString);

            return(repo.GetTopFive());
        }
Example #26
0
 public BookmarkManager(BookmarkRepository bookmarkRepository)
 {
     _bookmarkRepository = bookmarkRepository;
 }
 public BookmarksController()
 {
     //Todo: Use DI container for resolving dependencies :)
     _bookmarkRepository = new BookmarkRepository(new RavenSessionFactory());
     _bookmarkService = new BookmarkService(_bookmarkRepository);
 }
Example #28
0
        public static async Task <BookmarkView> Insert(Bookmark bookmark, bool isNotAllowNet)
        {
            if (bookmark == null)
            {
                throw new ArgumentNullException(nameof(bookmark));
            }
            using (DbHelper db = new DbHelper())
            {
                // 处理URL
                bookmark.Url = bookmark.Url.Trim();
                if (await BookmarkRepository.IsExistUrl(db, bookmark.CatalogId, bookmark.Url))
                {
                    throw new Exception("该目录已存在此URL,请勿重复增加");
                }
                // 处理title
                if (string.IsNullOrWhiteSpace(bookmark.Title))
                {
                    if (!isNotAllowNet)
                    {
                        bookmark.Title = await NetHelper.GetTitle(bookmark.Url);
                    }
                }
                bookmark.Title = bookmark.Title.Replace(System.Environment.NewLine, " ");
                // 处理Site
                string host      = NetHelper.GetHost(bookmark.Url);
                Site   site      = null;
                bool   isNewSite = false;
                if (await SiteRepository.IsExist(db, host))
                {
                    site = await SiteRepository.GetSiteWithHostAsync(db, host);

                    isNewSite = false;
                }
                else
                {
                    byte[] icon = null;
                    if (isNotAllowNet)
                    {
                        icon = ObjectHelper.ImageToByte(BookmarkManager.Properties.Resources.Hyperlink);
                    }
                    else
                    {
                        icon = NetHelper.GetFavicon(bookmark.Url);
                    }
                    site = new Site {
                        Id = Guid.NewGuid().ToString(), Host = host, Icon = icon
                    };
                    isNewSite = true;
                }
                bookmark.SiteId = site.Id;
                // 修改数据库
                using (var trans = db.BeginTransaction())
                {
                    try
                    {
                        if (isNewSite)
                        {
                            await SiteRepository.Insert(db, site);
                        }
                        await BookmarkRepository.Insert(db, bookmark);

                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.Rollback();
                        throw;
                    }
                }
                return(await BookmarkViewRepository.GetById(db, bookmark.Id));
            }
        }
Example #29
0
        public async Task <IActionResult> Display(int id, int page = 1, int target = -1)
        {
            var topic = await DbContext.Topics.FindAsync(id);

            if (topic is null || topic.Deleted)
            {
                throw new HttpNotFoundError();
            }

            if (page < 1)
            {
                var redirectUrl = Url.Action(nameof(Display), new { id, page = 1, target });
                return(Redirect(redirectUrl));
            }

            var messageIds = MessageRepository.GetMessageIds(topic.Id);

            if (target >= 0)
            {
                var targetPage = MessageRepository.GetPageNumber(target, messageIds);

                if (targetPage != page)
                {
                    return(Redirect(GetRedirectPath(id, targetPage, target)));
                }
            }

            var take           = CurrentUser.ApplicationUser.MessagesPerPage;
            var skip           = take * (page - 1);
            var totalPages     = Convert.ToInt32(Math.Ceiling(1.0 * messageIds.Count / take));
            var pageMessageIds = messageIds.Skip(skip).Take(take).ToList();

            var viewModel = new ViewModels.Topics.TopicDisplayPage {
                Id              = topic.Id,
                FirstMessageId  = topic.FirstMessageId,
                Subject         = string.IsNullOrEmpty(topic.FirstMessageShortPreview) ? "No subject" : topic.FirstMessageShortPreview,
                AssignedBoards  = new List <ViewModels.Boards.IndexBoard>(),
                IsAuthenticated = CurrentUser.IsAuthenticated,
                IsOwner         = topic.FirstMessagePostedById == CurrentUser.Id,
                IsAdmin         = CurrentUser.IsAdmin,
                IsPinned        = topic.Pinned,
                ShowFavicons    = CurrentUser.ApplicationUser.ShowFavicons,
                TotalPages      = totalPages,
                ReplyCount      = topic.ReplyCount,
                ViewCount       = topic.ViewCount,
                CurrentPage     = page,
                ReplyForm       = new ViewModels.Messages.ReplyForm {
                    Id        = "0",
                    TopicId   = topic.Id.ToString(),
                    ElementId = "topic-reply"
                }
            };

            await isBookmarked();
            await loadMessages();
            await loadCategories();
            await loadTopicBoards();
            await loadSmileyViewData();

            return(await ForumViewResult.ViewResult(this, viewModel));

            async Task isBookmarked()
            {
                viewModel.IsBookmarked = await BookmarkRepository.IsBookmarked(topic.Id);
            }

            async Task loadMessages()
            {
                viewModel.Messages = await MessageRepository.GetMessages(pageMessageIds);

                var latestMessageTime = viewModel.Messages.Max(r => r.RecordTime);
                await TopicRepository.MarkRead(topic.Id, latestMessageTime, pageMessageIds);

                topic.ViewCount++;
                DbContext.Update(topic);
                await DbContext.SaveChangesAsync();
            }

            async Task loadCategories()
            {
                viewModel.Categories = await BoardRepository.CategoryIndex();
            }

            async Task loadTopicBoards()
            {
                var topicBoards = await BoardRepository.GetTopicBoards(topic.Id);

                foreach (var topicBoard in topicBoards)
                {
                    var indexBoard = await BoardRepository.GetIndexBoard(topicBoard);

                    viewModel.AssignedBoards.Add(indexBoard);
                }
            }

            async Task loadSmileyViewData()
            {
                ViewData[Constants.InternalKeys.SmileyViewData] = await SmileyRepository.GetSelectorList();
            }
        }
Example #30
0
        public void DeleteBookmark(DeleteBookmarkViewModel vm)
        {
            var repo = new BookmarkRepository(_connectionString);

            repo.DeleteBookmark(vm.BookmarkId);
        }
Example #31
0
        public void DeleteBookmark(Bookmark bookmark)
        {
            var repo = new BookmarkRepository(_connectionString);

            repo.DeleteBookmark(bookmark.Id);
        }
Example #32
0
        public async Task <PageModels.TopicDisplayPage> GetDisplayPageModel(int id, int pageId = 1, int targetId = -1)
        {
            var viewModel = new PageModels.TopicDisplayPage();

            var record = DbContext.Messages.Find(id);

            if (record is null)
            {
                throw new HttpNotFoundError();
            }

            var topicId = id;

            if (record.ParentId > 0)
            {
                topicId = record.ParentId;
            }

            var messageIds = MessageRepository.GetMessageIds(topicId);

            if (topicId != id)
            {
                viewModel.RedirectPath = GetRedirectPath(id, record.ParentId, messageIds);
            }
            else if (targetId >= 0)
            {
                var targetPage = MessageRepository.GetPageNumber(targetId, messageIds);

                if (targetPage != pageId)
                {
                    viewModel.RedirectPath = GetRedirectPath(targetId, id, messageIds);
                }
            }

            if (string.IsNullOrEmpty(viewModel.RedirectPath))
            {
                var bookmarked = (await BookmarkRepository.Records()).Any(r => r.MessageId == topicId);

                var assignedBoards = await LoadTopicBoards(topicId);

                if (pageId < 1)
                {
                    pageId = 1;
                }

                var take       = UserContext.ApplicationUser.MessagesPerPage;
                var skip       = take * (pageId - 1);
                var totalPages = Convert.ToInt32(Math.Ceiling(1.0 * messageIds.Count / take));

                var pageMessageIds = messageIds.Skip(skip).Take(take).ToList();

                record.ViewCount++;
                DbContext.Update(record);
                DbContext.SaveChanges();

                var messages = await MessageRepository.GetMessages(pageMessageIds);

                if (string.IsNullOrEmpty(record.ShortPreview))
                {
                    record.ShortPreview = "No subject";
                }

                viewModel = new PageModels.TopicDisplayPage {
                    Id          = record.Id,
                    TopicHeader = new ItemModels.TopicHeader {
                        StartedById = record.PostedById,
                        Subject     = record.ShortPreview,
                        Views       = record.ViewCount,
                    },
                    Messages        = messages,
                    Categories      = await BoardRepository.CategoryIndex(),
                    AssignedBoards  = new List <ViewModels.Boards.Items.IndexBoard>(),
                    IsAuthenticated = UserContext.IsAuthenticated,
                    IsOwner         = record.PostedById == UserContext.ApplicationUser?.Id,
                    IsAdmin         = UserContext.IsAdmin,
                    IsBookmarked    = bookmarked,
                    IsPinned        = record.Pinned,
                    ShowFavicons    = UserContext.ApplicationUser.ShowFavicons,
                    TotalPages      = totalPages,
                    ReplyCount      = record.ReplyCount,
                    ViewCount       = record.ViewCount,
                    CurrentPage     = pageId,
                    ReplyForm       = new ViewModels.Messages.ReplyForm
                    {
                        Id        = record.Id.ToString(),
                        ElementId = $"topic-reply"
                    }
                };

                foreach (var assignedBoard in assignedBoards)
                {
                    var indexBoard = await BoardRepository.GetIndexBoard(assignedBoard);

                    viewModel.AssignedBoards.Add(indexBoard);
                }

                var latestMessageTime = messages.Max(r => r.RecordTime);

                TopicRepository.MarkRead(topicId, latestMessageTime, pageMessageIds);
            }

            return(viewModel);
        }