|
|
|
@@ -46,21 +46,40 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
return await _context.Files.ToListAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<IEnumerable<FileEntity>> GetAllFilesBasedOnContent(String content) |
|
|
|
{ |
|
|
|
using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); |
|
|
|
|
|
|
|
var sql = @"select * from Files inner join DocumentOrganizerDocStore on Files.DocumentId = DocumentOrganizerDocStore.stream_id |
|
|
|
where contains(DocumentOrganizerDocStore.file_stream,@content)"; |
|
|
|
|
|
|
|
var files = await connection.QueryAsync<FileEntity>(sql,new {content=content}); |
|
|
|
return files.ToList(); |
|
|
|
} |
|
|
|
public async Task<object> GetAllFiltered(FileFilter filters) |
|
|
|
{ |
|
|
|
using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); |
|
|
|
|
|
|
|
var sql = @"SELECT Files.Id as FileId, stream_id, DocumentOrganizerDocStore.name as FileName, file_stream, file_type, cached_file_size, Title, Tags.Id as TagId, Tags.Name as TagName, Categories.Id as CategoryId, Categories.Name as CategoryName |
|
|
|
FROM Files inner join FileEntityTag on Files.Id = FileEntityTag.FilesId |
|
|
|
inner join Tags on FileEntityTag.TagsId = Tags.Id |
|
|
|
inner join Categories on Files.CategoryId = Categories.Id |
|
|
|
inner join DocumentOrganizerDocStore on DocumentOrganizerDocStore.stream_id = Files.DocumentId" + |
|
|
|
(filters.Content is null ? "" : $" where contains(DocumentOrganizerDocStore.file_stream,@content);"); |
|
|
|
|
|
|
|
var files = await connection.QueryAsync<FileFilterReturnDto, TagResponse, CategoryResponse, FileFilterReturnDto>("SELECT Files.Id as FileId, stream_id, DocumentOrganizerDocStore.name as FileName, file_stream, file_type, cached_file_size, Title, Tags.Id as TagId, Tags.Name as TagName, Categories.Id as CategoryId, Categories.Name as CategoryName FROM Files inner join FileEntityTag on Files.Id = FileEntityTag.FilesId inner join Tags on FileEntityTag.TagsId = Tags.Id inner join DocumentOrganizerDocStore on DocumentOrganizerDocStore.stream_id = Files.DocumentId inner join Categories on Files.CategoryId = Categories.Id;", (file, tag, category) => |
|
|
|
var files = await connection.QueryAsync<FileFilterReturnDto, TagResponse, CategoryResponse, FileFilterReturnDto>(sql,(file, tag, category) => |
|
|
|
{ |
|
|
|
file.Tags.Add(tag); |
|
|
|
file.Category = category; |
|
|
|
return file; |
|
|
|
}, splitOn: "TagId, CategoryId"); |
|
|
|
}, splitOn: "TagId, CategoryId", |
|
|
|
param:new {content = filters.Content}); |
|
|
|
|
|
|
|
var filesList = files.ToList(); |
|
|
|
|
|
|
|
var filtered = filesList |
|
|
|
.FilterFiles(filters); |
|
|
|
.FilterFiles(filters) |
|
|
|
.DistinctBy(x => x.stream_id).ToList(); |
|
|
|
|
|
|
|
return new |
|
|
|
{ |