public List <AvailableDiagram> GetAvailableDiagrams(GetAvailableDiagramsParams param)
        {
            var filter = new DiagramMetaFilter
            {
                FilterTitle = param.FilterTitle,
                Sort        = param.Sort,
                Direction   = param.Direction,
                Batch       = param.Batch
            };
            var meta = _dbContext.RepositoryFactory.Get <IDiagramMetaRepository>().GetDiagramMeta(filter);
            var availableDiagrams = meta.Select(x => new AvailableDiagram {
                Id = x.DiagramId, Title = x.Title
            }).ToList();

            if (param.IncludeThumbnails)
            {
                var diagramThumbnailRepo = _dbContext.RepositoryFactory.Get <IDiagramThumbnailRepository>();
                var thumbnails           = diagramThumbnailRepo.Get(availableDiagrams).ToDictionary(k => k.DiagramId, v => v.Content);
                foreach (var availableDiagram in availableDiagrams)
                {
                    if (thumbnails.ContainsKey(availableDiagram.Id))
                    {
                        availableDiagram.Thumbnail = "data:image/jpg;base64," + thumbnails[availableDiagram.Id];
                    }
                }
            }

            return(availableDiagrams);
        }
        public IEnumerable <DiagramMeta> GetDiagramMeta(DiagramMetaFilter filter)
        {
            var query = Engine.GetCollection <DiagramMeta>().Query()
                        .Select();

            var direction = filter.Direction == Utils.SortDirection.Asc ? SortDirection.Asc : SortDirection.Desc;

            if (filter.Sort == DiagramSortField.Title)
            {
                query = query
                        .OrderBy(x => x.TitleLetter, direction)
                        .OrderBy(x => x.TitleNumber, direction);
            }
            else if (filter.Sort == DiagramSortField.CreateDate)
            {
                query = query.OrderBy(x => x.CreateDate, direction);
            }
            else if (filter.Sort == DiagramSortField.UpdateDate)
            {
                query = query.OrderBy(x => x.UpdateDate, direction);
            }

            if (!String.IsNullOrWhiteSpace(filter.FilterTitle))
            {
                query = query.Where(x => x.Title.Contains(filter.FilterTitle));
            }

            var result = filter.Batch != null?query.Skip(filter.Batch.StartIndex).Limit(filter.Batch.Count).ToList() : query.ToList();

            return(result);
        }
Exemple #3
0
        public IEnumerable <DiagramMeta> GetDiagramMeta(DiagramMetaFilter filter)
        {
            var query = DatabaseFile.GetCollection <DiagramMeta>().Query();

            if (filter.Sort == DiagramSortField.Title && filter.Direction == SortDirection.Asc)
            {
                query = query.OrderBy(x => new { x.TitleLetter, x.TitleNumber });
            }
            else if (filter.Sort == DiagramSortField.Title && filter.Direction == SortDirection.Desc)
            {
                query = query.OrderByDescending(x => new { x.TitleLetter, x.TitleNumber });
            }
            else if (filter.Sort == DiagramSortField.CreateDate && filter.Direction == SortDirection.Asc)
            {
                query = query.OrderBy(x => x.CreateDate);
            }
            else if (filter.Sort == DiagramSortField.CreateDate && filter.Direction == SortDirection.Desc)
            {
                query = query.OrderByDescending(x => x.CreateDate);
            }
            else if (filter.Sort == DiagramSortField.UpdateDate && filter.Direction == SortDirection.Asc)
            {
                query = query.OrderBy(x => x.UpdateDate);
            }
            else if (filter.Sort == DiagramSortField.UpdateDate && filter.Direction == SortDirection.Desc)
            {
                query = query.OrderByDescending(x => x.UpdateDate);
            }

            if (!String.IsNullOrWhiteSpace(filter.FilterTitle))
            {
                query = query.Where(x => x.Title.Contains(filter.FilterTitle));
            }

            var result = filter.Batch != null?query.Skip(filter.Batch.StartIndex).Limit(filter.Batch.Count).ToList() : query.ToList();

            return(result);
        }