Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] BookmarkDto bookmarkDto)
        {
            var userId = int.Parse(this.User.Identity.Name);

            var bookmark = new Bookmark().PopulateWith(bookmarkDto);

            bookmark.CreatedById  = userId;
            bookmark.ModifiedById = userId;

            BookmarkDto dto = null;

            try
            {
                // save
                bookmark = await _bookmarksRepository.Create(bookmark);

                dto = GetDtoById(bookmark.Id);
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }

            await _hubContext.SendMessage(new HubMessage
            {
                Action = HUBMESSAGE_BOOKMARK_CREATED,
                Data   = new Dictionary <string, object>
                {
                    { "bookmark", dto }
                }
            });

            return(Ok(dto));
        }
Exemplo n.º 2
0
        public IActionResult GetAll(
            [FromQuery(Name = "skip")] int skip = 0, [FromQuery(Name = "take")] int take = 0, [FromQuery(Name = "q")] string q = null)
        {
            var query =
                _bookmarksRepository.GetAll().OrderByDescending(d => d.CreateDate)
                .Where(r =>
                       r.Title.Contains(q ?? "", StringComparison.OrdinalIgnoreCase) || (
                           r.Description != null && r.Description.Contains(q ?? "", StringComparison.OrdinalIgnoreCase))
                       );
            var bookmarks = (skip >= 0 && take > 0) ?
                            query
                            .Skip(skip)
                            .Take(take)
                            .ToList() :
                            query.ToList();
            var createdByIds  = bookmarks.Select(b => b.CreatedById).Distinct();
            var modifiedByIds = bookmarks.Select(b => b.ModifiedById).Distinct();
            var users         = _authRepository.GetAll().Where(u => createdByIds.Contains(u.Id) || modifiedByIds.Contains(u.Id)).ToList();

            var dtos = new List <BookmarkDto>();

            foreach (var bookmark in bookmarks)
            {
                var dto = new BookmarkDto().PopulateWith(bookmark);
                dto.CreatedBy  = users.FirstOrDefault(u => u.Id == bookmark.CreatedById)?.ConvertTo <UserInfo>();
                dto.ModifiedBy = users.FirstOrDefault(u => u.Id == bookmark.ModifiedById)?.ConvertTo <UserInfo>();
                dto.MetaTags   = bookmark.MetaTagsJson?.FromJson <List <Dictionary <string, object> > >();
                dtos.Add(dto);
            }

            return(Ok(dtos));
        }
Exemplo n.º 3
0
        private void AddBookmarkDtoAsSearchResult(BookmarkDto bookmark, int resultIndex)
        {
            if (bookmark != null)
            {
                // Create pill with embedded bookmark id
                var resultPill = Pill.CreatePill(Pill.PillStyle_Unselected, bookmark.Title);

                // Add the right click context menu
                // Tag stores the result index and the bookmark id
                // This is a different thing than the tags stored in bookmarks
                resultPill.Tag = new Tuple <int, int>(resultIndex, bookmark.Id);
                ContextMenu pillMenu = new ContextMenu();
                resultPill.ContextMenu = pillMenu;
                // Edit
                MenuItem editBookmarkCommand = new MenuItem();
                editBookmarkCommand.Header = "Edit";
                editBookmarkCommand.Click += EditBookmarkCommand_Click;
                pillMenu.Items.Add(editBookmarkCommand);
                // Delete
                MenuItem deleteBookmarkCommand = new MenuItem();
                deleteBookmarkCommand.Header = "Delete";
                deleteBookmarkCommand.Click += DeleteBookmarkCommand_Click;
                pillMenu.Items.Add(deleteBookmarkCommand);

                // Add a right mouse down event that highlights the item being right clicked on
                resultPill.MouseDown += ResultPill_MouseDown;

                stackResult.Children.Add(resultPill);
            }
        }
Exemplo n.º 4
0
        public void AddBookmark(string username, BookmarkDto bookmark)
        {
            bookmark.AuditCreate(username);
            var entity = Mapper.Map <Bookmark>(bookmark);

            _bookmarksesRepository.Insert(entity);
        }
Exemplo n.º 5
0
        public void UpdateBookmark(string username, BookmarkDto bookmark)
        {
            bookmark.AuditUpdate(username);
            var entity = Mapper.Map <Bookmark>(bookmark);

            _bookmarksesRepository.Replace(entity);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Delete(Guid id)
        {
            BookmarkDto dto = null;

            try
            {
                _bookmarksRepository.Delete(id);
                dto = new BookmarkDto {
                    Id = id
                };
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }

            await _hubContext.SendMessage(new HubMessage
            {
                Action = HUBMESSAGE_BOOKMARK_DELETED,
                Data   = new Dictionary <string, object>
                {
                    { "bookmark", dto }
                }
            });

            return(Ok());
        }
Exemplo n.º 7
0
        public void RemoveBookmark(BookmarkDto bookmark)
        {
            BookmarkRepository.Delete(new Bookmark()
            {
                Name = bookmark.Name,
                Url  = bookmark.Url
            });

            UnitOfWork.Commit();
        }
Exemplo n.º 8
0
        public void AddBookmark(BookmarkDto bookmark)
        {
            BookmarkRepository.Create(new Bookmark()
            {
                Name = bookmark.Name,
                Url  = bookmark.Url
            });

            UnitOfWork.Commit();
        }
Exemplo n.º 9
0
        public BookmarkDto Get(int id)
        {
            Bookmark bkm = _businessLocator.BookmarkBll.GetBookmarksByCriteria(x => x.Id == id).FirstOrDefault();

            if (bkm != null)
            {
                BookmarkDto bkmDto = new BookmarkDto(bkm);
                return(bkmDto);
            }
            return(null);
        }
        private BookmarkDto CreateBookmarkDto(Bookmark bookmark)
        {
            var dto = new BookmarkDto();

            dto.Link       = Url.Link(nameof(GetBookmark), new { bookmark.BookmarkId });
            dto.BookmarkId = bookmark.BookmarkId;
            dto.PostLink   = Url.Link(nameof(PostsController.GetPost), new { bookmark.PostId });
            dto.PostId     = bookmark.PostId;
            dto.Note       = bookmark.Note;

            return(dto);
        }
Exemplo n.º 11
0
        public BookmarkDto CreateBookmark(BookmarkDto a)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var abc = Mapper.Map <BookmarkDto, Bookmark>(a);

            context.Bookmarks.Add(abc);
            context.SaveChanges();
            return(a);
        }
Exemplo n.º 12
0
        /*******************************************************
        * Helpers
        * *****************************************************/


        private BookmarkListModel CreateBookmarkListModel(BookmarkDto bookmark)
        {
            var model = new BookmarkListModel
            {
                Type     = bookmark.Posttype,
                ParentID = bookmark.ParentID,
                PostID   = bookmark.PostID,
                Title    = bookmark.Title,
                UserID   = bookmark.UserID,
            };

            model.Url = CreateBookmarkLink(bookmark.PostID);
            return(model);
        }
Exemplo n.º 13
0
        private BookmarkDto GetDtoById(Guid id)
        {
            var bookmark   = _bookmarksRepository.GetById(id);
            var createdBy  = _authRepository.GetById(bookmark.CreatedById)?.ConvertTo <UserInfo>();
            var modifiedBy = _authRepository.GetById(bookmark.ModifiedById)?.ConvertTo <UserInfo>();

            var dto = new BookmarkDto().PopulateWith(bookmark);

            dto.CreatedBy  = createdBy;
            dto.ModifiedBy = modifiedBy;
            dto.MetaTags   = bookmark.MetaTagsJson?.FromJson <List <Dictionary <string, object> > >();

            return(dto);
        }
Exemplo n.º 14
0
        public async Task <ActionResult> Bookmark(BookmarkDto bookmarkDto)
        {
            var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());

            _logger.LogDebug("Saving {UserName} progress for Chapter {ChapterId} to page {PageNum}", user.UserName, bookmarkDto.ChapterId, bookmarkDto.PageNum);

            // Don't let user bookmark past total pages.
            var chapter = await _unitOfWork.VolumeRepository.GetChapterAsync(bookmarkDto.ChapterId);

            if (bookmarkDto.PageNum > chapter.Pages)
            {
                return(BadRequest("Can't bookmark past max pages"));
            }

            if (bookmarkDto.PageNum < 0)
            {
                return(BadRequest("Can't bookmark less than 0"));
            }


            user.Progresses ??= new List <AppUserProgress>();
            var userProgress = user.Progresses.SingleOrDefault(x => x.ChapterId == bookmarkDto.ChapterId && x.AppUserId == user.Id);

            if (userProgress == null)
            {
                user.Progresses.Add(new AppUserProgress
                {
                    PagesRead = bookmarkDto.PageNum,
                    VolumeId  = bookmarkDto.VolumeId,
                    SeriesId  = bookmarkDto.SeriesId,
                    ChapterId = bookmarkDto.ChapterId
                });
            }
            else
            {
                userProgress.PagesRead = bookmarkDto.PageNum;
                userProgress.SeriesId  = bookmarkDto.SeriesId;
                userProgress.VolumeId  = bookmarkDto.VolumeId;
            }

            _unitOfWork.UserRepository.Update(user);

            if (await _unitOfWork.Complete())
            {
                return(Ok());
            }

            return(BadRequest("Could not save progress"));
        }
Exemplo n.º 15
0
        public void UpdateBookmark(int id, BookmarkDto bookmarkDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var admin = context.Bookmarks.SingleOrDefault(c => c.Bookmark_ID == id);

            if (admin == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            Mapper.Map(bookmarkDto, admin);
            context.SaveChanges();
        }
Exemplo n.º 16
0
        public void ShowEditor(int?bookmarkIdToEdit)
        {
            if (bookmarkIdToEdit == null)
            {
                bookmark = new BookmarkDto();

                // If we are creating a new entry then check the clipboard, there might be
                // something copied there that we can auto-paste into the url field.
                var clipboardUrl = ClipboardUtil.GetUrlFromClipboard(checkFormat: true);
                if (!string.IsNullOrWhiteSpace(clipboardUrl))
                {
                    bookmark.Url = clipboardUrl;
                }
            }
            else
            {
                bookmark = DataProvider.DataStore.Value.Bookmarks.Value.Get(bookmarkIdToEdit.Value);
            }

            RenderBookmark();
            this.ShowDialog();
        }
Exemplo n.º 17
0
 public IActionResult Put([FromBody] BookmarkDto bookmark)
 {
     _bookmarkService.UpdateBookmark(User.Identity.GetClaim("name"), bookmark);
     return(Ok());
 }
Exemplo n.º 18
0
 public IActionResult Delete([FromBody] BookmarkDto bookmark)
 {
     BookmarkService.RemoveBookmark(bookmark);
     return(Ok("Bookmark was removed successfully!"));
 }
Exemplo n.º 19
0
 public IActionResult Post([FromBody] BookmarkDto bookmark)
 {
     BookmarkService.AddBookmark(bookmark);
     return(Ok("Bookmark was added successfully!"));
 }