Exemple #1
0
 public Task <DraftCollection> List([FromQuery] DraftQuery query)
 {
     if (query.File == null)
     {
         //Check url query, if file was in it we are looking for the default file (index usually)
         var hasFile = HttpContext.Request.Query.Any(i => "file".Equals(i.Key, StringComparison.OrdinalIgnoreCase));
         if (hasFile)
         {
             query.File = "";
         }
     }
     return(draftRepo.List(query));
 }
        /// <summary>
        /// Get the list of pages in draft.
        /// </summary>
        /// <returns>The list of drafted files.</returns>
        public async Task <DraftCollection> List(DraftQuery query)
        {
            DraftCollection collection;

            if (query.File != null) //If file is not null, looking for specific file.
            {
                collection = new DraftCollection(query, 1, new Draft[] { await GetInfo(query.File) });
            }
            else
            {
                IEnumerable <DraftInfo> draftQuery;
                int total = 0;
                if (query.ShowChangedOnly)
                {
                    draftQuery = fileFinder.GetAllDraftables()
                                 .Select(i => fileFinder.GetDraftStatus(i))
                                 .Where(i => i.Status != DraftStatus.UpToDate)
                                 .ToList(); //Cache this in a list, it is slow
                    total      = draftQuery.Count();
                    draftQuery = draftQuery
                                 .Skip(query.SkipTo(total))
                                 .Take(query.Limit);
                }
                else
                {
                    var draftables = fileFinder.GetAllDraftables();
                    total      = draftables.Count();
                    draftQuery = draftables
                                 .Skip(query.SkipTo(total))
                                 .Take(query.Limit)
                                 .Select(i => fileFinder.GetDraftStatus(i));
                }

                var convert = draftQuery.Select(i =>
                {
                    var fileInfo     = fileInfoProvider.GetFileInfo(i.File, pathBase);
                    var pageSettings = fileFinder.GetProjectPageDefinition(fileInfo);
                    return(new Draft(i, pageSettings.Title));
                });
                collection = new DraftCollection(query, total, convert);
            }

            return(collection);
        }