Ejemplo n.º 1
0
        public ViewResult Edit(int bookmarkID, User currentUser)
        {
            var bookmark = _bookmarkRepository.Bookmarks.FirstOrDefault(x => x.BookmarkID == bookmarkID);
            if (bookmark == null)
            {
                bookmark = new Bookmark { BookmarkID = 0, UserID = currentUser.UserId };
            }

            BookmarkViewModel model = new BookmarkViewModel { Bookmark = bookmark };
            model.Tags = (from t in _bookmarkRepository.Tags
                          from bt in _bookmarkRepository.BookmarkTags
                          where bt.TagID == t.TagID &&
                          bt.BookmarkID == bookmark.BookmarkID
                          select t).ToList();

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(BookmarkViewModel model, User user)
        {
            /*
            Bookmark bookmark = model.Bookmark.BookmarkID == 0 ? new Bookmark() : _bookmarkRepository.Bookmarks.First(x => x.BookmarkID == model.Bookmark.BookmarkID);
            TryUpdateModel(bookmark, "Bookmark");

            if (ModelState.IsValid)
            {
                bookmark.UserID = user.UserId;
                _bookmarkRepository.SaveBookmark(bookmark);

                // Clear out the old tags
                _bookmarkRepository.ClearBookmarkTags(bookmark.BookmarkID);

                // Save the tags
                foreach (var tagName in model.Tags.ToTagList())
                {
                    var tag = _bookmarkRepository.Tags.FirstOrDefault(x => x.Name.Trim() == tagName.Trim());

                    if (tag == null)
                    {
                        tag = new Tag { Name = tagName, TagID = 0 };
                    }

                    _bookmarkRepository.SaveTag(tag);
                    _bookmarkRepository.SaveBookmarkTag(
                            new BookmarkTag { BookmarkID = bookmark.BookmarkID, TagID = tag.TagID }
                        );
                }

                TempData["message"] = "Your bookmark has been saved";
                return RedirectToAction("Index");
            }
            else
            {
                return View(model);
            }
             * */
            return View();
        }
Ejemplo n.º 3
0
        public ViewResult Index([DefaultValue(1)]int page)
        {
            var bookmarks = _bookmarkRepository.Bookmarks.Skip((page - 1) * PageSize).Take(PageSize).ToList();
            var bookmarkList = new BookmarksListViewModel();

            // Build the viewmodel for each bookmark
            foreach (Bookmark bookmark in bookmarks)
            {
                BookmarkViewModel model = new BookmarkViewModel { Bookmark = bookmark };
                model.Tags = (from t in _bookmarkRepository.Tags
                              from bt in _bookmarkRepository.BookmarkTags
                              where bt.TagID == t.TagID &&
                              bt.BookmarkID == bookmark.BookmarkID
                              select t).ToList();

                bookmarkList.Bookmarks.Add(model);
            }

            bookmarkList.PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    ItemsPerPage = PageSize,
                    TotalItems = _bookmarkRepository.Bookmarks.Count()
                };

            return View(bookmarkList);
        }
Ejemplo n.º 4
0
 public ActionResult New(User currentUser)
 {
     var model = new BookmarkViewModel { Bookmark = new Bookmark { BookmarkID = 0, UserID = currentUser.UserId }, Tags = new List<Tag>() };
     return View("Edit", model);
 }