public IActionResult GetDocumentsWithoutFilePaged(
            [FromHeader(Name = "Authorization")] string token,
            long?page,
            long?pageSize,
            long?publicationDate,
            string number,
            string orderBy      = "DEFAULT",
            bool descend        = false,
            long?entityId       = null,
            long?documentTypeId = null
            )
        {
            var msg = new DocumentsWithoutFilePageMessage {
                PageSize = pageSize,
                Page     = page,
                OrderBy  = orderBy,
                Descend  = descend,

                PublicationYear = publicationDate,
                Number          = number,
                EntityId        = entityId,
                DocumentTypeId  = documentTypeId
            };

            return(withoutFileQuery.Execute(msg, token)
                   .Match(
                       Succ: x => Ok(x),
                       Fail: ex => StatusCode(500, ex)
                       ));
        }
Exemple #2
0
        public PagedResult <Document> GetPageOfDocumentsWithoutFile(DocumentsWithoutFilePageMessage msg, string token)
        {
            var page     = msg.Page ?? 1;
            var pageSize = msg.PageSize ?? 10;
            var desc     = msg.Descend ?? false;
            var skip     = (int)((page - 1) * pageSize);

            var entity = context.Credentials
                         .Where(c => c.Token == token)
                         .Select(c => c.User.Entity);

            var documentsWithoutFile = context.Documents
                                       .Include(x => x.File)
                                       .Where(x => x.File == null);

            documentsWithoutFile = msg.DocumentTypeId.HasValue
        ? (msg.DocumentTypeId.Value > 0
          ? documentsWithoutFile.Where(d => d.DocumentTypeId == msg.DocumentTypeId.Value)
          : documentsWithoutFile)
        : documentsWithoutFile;

            var entityDomain = entity.FirstOrDefault();

            if (entityDomain == null)
            {
                documentsWithoutFile = msg.EntityId.HasValue
          ? (msg.EntityId.Value > 0
            ? documentsWithoutFile.Where(d => d.EntityId == msg.EntityId.Value)
            : documentsWithoutFile)
          : documentsWithoutFile;
            }
            else
            {
                documentsWithoutFile = documentsWithoutFile.Where(d => d.EntityId == entityDomain.Id);
            }

            documentsWithoutFile = msg.Number != null
        ? documentsWithoutFile.Where(d => d.Number == msg.Number)
        : documentsWithoutFile;

            documentsWithoutFile = msg.PublicationYear.HasValue
        ? (msg.PublicationYear.Value > 0
          ? documentsWithoutFile.Where(d => d.PublicationYear == msg.PublicationYear.Value)
          : documentsWithoutFile)
        : documentsWithoutFile;

            IQueryable <Document> pagedQuery;

            var keySelector = GetOrderProperty(msg.OrderBy);

            if (desc)
            {
                pagedQuery = documentsWithoutFile.OrderByDescending(keySelector);
            }
            else
            {
                pagedQuery = documentsWithoutFile.OrderBy(keySelector);
            }

            return(new PagedResult <Document> {
                Count = documentsWithoutFile.Count(),
                Page = pagedQuery.Skip(skip).Take((int)pageSize).AsQueryable()
            });
        }