// ----------- // Preview // ----------- public Task <IActionResult> Preview(EntityAttachmentOptions opts) { if (opts == null) { opts = new EntityAttachmentOptions(); } // We always need a guid if (string.IsNullOrEmpty(opts.Guid)) { throw new ArgumentNullException(nameof(opts.Guid)); } // Return view return(Task.FromResult((IActionResult)View(opts))); }
public async Task <IViewComponentResult> InvokeAsync(EntityAttachmentOptions model) { // We always need a model if (model == null) { throw new ArgumentNullException(nameof(model)); } // We always need a guid if (string.IsNullOrEmpty(model.Guid)) { throw new ArgumentNullException(nameof(model.Guid)); } // Get data & return view return(View(new AttachmentsViewModel() { Results = await GetDataAsync(model) })); }
private async Task <IPagedResults <Attachment> > GetDataAsync(EntityAttachmentOptions model) { return(await _attachmentStore .QueryAsync() .Select <AttachmentQueryParams>(async q => { // Get attachments for entity if (model.EntityId > 0) { var relaationships = await _entityAttachmentStore .GetByEntityIdAsync(model.EntityId); if (relaationships != null) { q.Id.IsIn(relaationships.Select(r => r.AttachmentId).ToArray()); } } // Get attachments for guid q.ContentGuid.Or().Equals(model.Guid); }) .ToList()); }