Example #1
0
        public FolderContentsModel GetFolderContents(Guid userId, Guid folderId, int docId, int pos)
        {
            FolderContentsModel folderContents = new FolderContentsModel {
            };

            BookmarkGetModel bookmarksGetModel = new BookmarkGetModel
            {
                UserId   = userId, //S* userId должен быть обязательным
                FolderId = folderId,
                DocId    = docId,
                Pos      = pos,
                FromPos  = 0,
                Count    = 1000,
                Sort     = DocsSort.ByAddDate
            };

            BookmarkResultModel receivedBookmarks = bookmarks.Get(bookmarksGetModel);

            foreach (List <BookmarkModel> topics in receivedBookmarks.Topics)
            {
                foreach (BookmarkModel subTopics in topics)
                {
                    var result = context.Folders.Where(x => x.Id == subTopics.FolderId).FirstOrDefault();

                    //folderContents.Folders.Add(GetFolderChilds(new FolderContentsModel { Id = result.Id, Name = result.Name }));
                }
                ;
            }
            ;

            return(folderContents);
        }
Example #2
0
        public BookmarkResultModel Get(BookmarkGetModel model)
        {//S* UserId должен быть обязательным
            var query = context.Bookmarks.Where(x => x.UserId == model.UserId);

            if (model.DocId > 0)
            {
                query = query.Where(x => x.DocId == model.DocId);

                if (model.Pos >= 0)
                {
                    query = query.Where(x => x.Page == model.Pos);
                }
            }
            else if (model.FolderId != Guid.Empty)
            {
                query = query.Where(x => x.FolderId == model.FolderId);
            }

            query = query.OrderBy(o => o.FolderId).ThenBy(o => o.DocId).ThenByDescending(o => o.DateAdd);

            var result = query.ToList();

            var topics = new List <List <BookmarkModel> >();
            int total  = 0;
            List <BookmarkModel> bookmarksList = new List <BookmarkModel>();

            foreach (var bk in result)
            {
                if (total > 0)
                {
                    if (total >= model.FromPos && total <= model.FromPos + model.Count)
                    {
                        topics.Add(bookmarksList);
                    }

                    bookmarksList = new List <BookmarkModel>();
                }
                total += 1;

                BookmarkModel bookmark = new BookmarkModel
                {
                    Id        = bk.Id,
                    DocId     = bk.DocId,
                    DateAdd   = bk.DateAdd,
                    Name      = bk.Name,
                    TopicName = bk.TopicName,
                    View      = bk.View,
                    Page      = bk.Page,
                    ScrollPos = bk.ScrollPos,
                    FolderId  = bk.FolderId
                };

                if (!DBNull.Value.Equals(bk.Cid))
                {
                    bookmark.Cid         = bk.Cid;
                    bookmark.Changed     = bk.Changed;
                    bookmark.Notificated = bk.Notificated;
                }

                bookmark.Noactive  = !DBNull.Value.Equals(bk.Noactive);
                bookmark.Preactive = !DBNull.Value.Equals(bk.Preactive);
                bookmarksList.Add(bookmark);
            }

            if (total > 0)
            {
                topics.Add(bookmarksList);
            }

            if (model.Sort == DocsSort.ByName)
            {
                topics = topics.OrderByDescending(b => b.First().TopicName).ToList();
            }
            else if (model.Sort == DocsSort.ByAddDate)
            {
                topics = topics.OrderByDescending(b => b.Max(b => b.DateAdd)).ToList();
            }

            BookmarkResultModel bmResult = new BookmarkResultModel();

            bmResult.Topics = topics;
            bmResult.Total  = total;

            if (topics.Count > 0)
            {
                bmResult.FirstPos = model.FromPos;
                bmResult.LastPos  = model.FromPos + topics.Count - 1;
            }
            else
            {
                bmResult.FirstPos = 0;
                bmResult.LastPos  = 0;
            }

            return(bmResult);
        }