| { | { | ||||
| using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | ||||
| 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, 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>("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) => | |||||
| { | { | ||||
| file.Tags.Add(tag); | file.Tags.Add(tag); | ||||
| file.Category = category; | file.Category = category; | ||||
| return new | return new | ||||
| { | { | ||||
| Data = filtered.ApplyPagging(filters) | Data = filtered.ApplyPagging(filters) | ||||
| .Select(n => new { n.stream_id, n.FileName, n.cached_file_size, n.file_type }), | |||||
| .Select(n => new { n.stream_id, n.FileName, n.cached_file_size, n.file_type, n.Title }), | |||||
| Total = filtered.Count | Total = filtered.Count | ||||
| }; | }; | ||||
| } | } |
| { | { | ||||
| public class CreateFileRequest | public class CreateFileRequest | ||||
| { | { | ||||
| public string Title { get; set; } | |||||
| public int CategoryId { get; set; } | public int CategoryId { get; set; } | ||||
| public int[] TagsIds { get; set; } | public int[] TagsIds { get; set; } |
| { | { | ||||
| public Guid stream_id { get; set; } | public Guid stream_id { get; set; } | ||||
| public string FileName { get; set; } | public string FileName { get; set; } | ||||
| public string Title { get; set; } | |||||
| public string file_type { get; set; } | public string file_type { get; set; } | ||||
| public int cached_file_size { get; set; } | public int cached_file_size { get; set; } | ||||
| public List<TagResponse> Tags { get; set; } = new(); | public List<TagResponse> Tags { get; set; } = new(); |
| { | { | ||||
| public int Id { get; set; } | public int Id { get; set; } | ||||
| public string Title { get; set; } | |||||
| public Guid DocumentId { get; set; } | public Guid DocumentId { get; set; } | ||||
| [ForeignKey(nameof(Category))] | [ForeignKey(nameof(Category))] |
| using Microsoft.EntityFrameworkCore.Migrations; | |||||
| #nullable disable | |||||
| namespace Diligent.WebAPI.Data.Migrations | |||||
| { | |||||
| public partial class AddedTitleToFileEntity : Migration | |||||
| { | |||||
| protected override void Up(MigrationBuilder migrationBuilder) | |||||
| { | |||||
| migrationBuilder.AddColumn<string>( | |||||
| name: "Title", | |||||
| table: "Files", | |||||
| type: "nvarchar(max)", | |||||
| nullable: false, | |||||
| defaultValue: ""); | |||||
| } | |||||
| protected override void Down(MigrationBuilder migrationBuilder) | |||||
| { | |||||
| migrationBuilder.DropColumn( | |||||
| name: "Title", | |||||
| table: "Files"); | |||||
| } | |||||
| } | |||||
| } |
| b.Property<Guid>("DocumentId") | b.Property<Guid>("DocumentId") | ||||
| .HasColumnType("uniqueidentifier"); | .HasColumnType("uniqueidentifier"); | ||||
| b.Property<string>("Title") | |||||
| .IsRequired() | |||||
| .HasColumnType("nvarchar(max)"); | |||||
| b.HasKey("Id"); | b.HasKey("Id"); | ||||
| b.HasIndex("CategoryId"); | b.HasIndex("CategoryId"); |
| var file = await _documentService.UploadDocument(request.FileToUpload); | var file = await _documentService.UploadDocument(request.FileToUpload); | ||||
| await _fileEntityService.UploadPdfAsync(new FileEntity { CategoryId = request.CategoryId, DocumentId = file.stream_id, Category = category, Tags = tags}); | |||||
| await _fileEntityService.UploadPdfAsync(new FileEntity { CategoryId = request.CategoryId, DocumentId = file.stream_id, Category = category, Tags = tags, Title = request.Title}); | |||||
| return Ok(); | return Ok(); | ||||
| } | } | ||||
| } | } |