public Task <IActionResult> Preview(EntityFileOptions opts) { if (opts == null) { opts = new EntityFileOptions(); } // We always need a guid if (string.IsNullOrEmpty(opts.Guid)) { throw new ArgumentNullException(nameof(opts.Guid)); } opts.PostPermission = Permissions.PostQuestionFiles; opts.DeleteOwnPermission = Permissions.DeleteOwnQuestionFiles; opts.DeleteAnyPermission = Permissions.DeleteAnyQuestionFiles; opts.DeleteRoute = new RouteValueDictionary() { ["area"] = ModuleId, ["controller"] = "Api", ["action"] = "Delete" }; // Return view return(Task.FromResult((IActionResult)View(opts))); }
private async Task <IPagedResults <File> > GetResultsAsync(EntityFileOptions model) { IEnumerable <EntityFile> relaationships = null; if (model.EntityId > 0) { relaationships = await _entityAttachmentStore .GetByEntityIdAsync(model.EntityId); } return(await _attachmentStore .QueryAsync() .Take(int.MaxValue, false) .Select <FileQueryParams>(q => { // Get attachments for entity if (relaationships != null) { q.Id.IsIn(relaationships.Select(r => r.FileId).ToArray()); } // Get attachments for guid q.ContentGuid.Equals(model.Guid).Or(); }) .OrderBy("TotalViews", OrderBy.Desc) .ToList()); }
public async Task <IViewComponentResult> InvokeAsync(EntityFileOptions 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 current authenticated user var user = _httpContextAccessor.HttpContext.Features[typeof(User)] as User; // Build model & return view return(View(new FilesViewModel() { Info = await _fileInfoStore.GetByUserIdAsync(user?.Id ?? 0), Options = await _fileOptionsFactory.GetOptionsAsync(user), Results = await GetResultsAsync(model), DeleteRoute = model.DeleteRoute, PostPermission = model.PostPermission, DeleteOwnPermission = model.DeleteOwnPermission, DeleteAnyPermission = model.DeleteAnyPermission })); }
public async Task <IViewComponentResult> InvokeAsync(EntityFileOptions 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)); } // Build model & return view return(View(new FilesViewModel() { Results = await GetResultsAsync(model), PostPermission = model.PostPermission, DeleteOwnPermission = model.DeleteOwnPermission, DeleteAnyPermission = model.DeleteAnyPermission })); }