| public async Task<object> GetAllFiltered(FileFilter filters) | public async Task<object> GetAllFiltered(FileFilter filters) | ||||
| { | { | ||||
| using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi")); | ||||
| var sql = @"SELECT Files.Id as FileId, Files.Deleted, 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 | |||||
| var sql = @"SELECT Files.Id as FileId, Note, Files.Deleted, 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 | FROM Files inner join FileEntityTag on Files.Id = FileEntityTag.FilesId | ||||
| inner join Tags on FileEntityTag.TagsId = Tags.Id | inner join Tags on FileEntityTag.TagsId = Tags.Id | ||||
| inner join Categories on Files.CategoryId = Categories.Id | inner join Categories on Files.CategoryId = Categories.Id | ||||
| FileName = fileItem.FileName, | FileName = fileItem.FileName, | ||||
| File_type = fileItem.File_type, | File_type = fileItem.File_type, | ||||
| Tags = fileItem.Tags, | Tags = fileItem.Tags, | ||||
| Title = fileItem.Title | |||||
| Title = fileItem.Title, | |||||
| Note = fileItem.Note | |||||
| }; | }; | ||||
| // return File_stream in base64 format | // return File_stream in base64 format | ||||
| MemoryStream stream = new (fileItem.File_stream); | MemoryStream stream = new (fileItem.File_stream); | ||||
| return new | return new | ||||
| { | { | ||||
| Data = filtered.ApplyPagging(filters) | Data = filtered.ApplyPagging(filters) | ||||
| .Select(n => new { n.Stream_id, n.FileName,n.File_stream, n.Cached_file_size, n.File_type, n.Title }), | |||||
| .Select(n => new { n.Stream_id, n.FileName,n.File_stream, n.Cached_file_size, n.File_type, n.Title, n.Note }), | |||||
| Total = filtered.Count | Total = filtered.Count | ||||
| }; | }; | ||||
| } | } | ||||
| await _context.SaveChangesAsync(); | await _context.SaveChangesAsync(); | ||||
| } | } | ||||
| public async Task UpdateNoteAsync(Guid id, UpdateFileNoteRequest fileDto) | |||||
| { | |||||
| var file = await GetFileEntityByIdAsync(id); | |||||
| file.Note = fileDto.Note; | |||||
| await _context.SaveChangesAsync(); | |||||
| } | |||||
| } | } | ||||
| } | } |
| Task UploadFileAsync(FileEntity file); | Task UploadFileAsync(FileEntity file); | ||||
| Task<object> GetAllFiltered(FileFilter filters); | Task<object> GetAllFiltered(FileFilter filters); | ||||
| Task<FileEntity> GetFileEntityByIdAsync(Guid id); | Task<FileEntity> GetFileEntityByIdAsync(Guid id); | ||||
| Task UpdateNoteAsync(Guid id, UpdateFileNoteRequest fileDto); | |||||
| Task DeleteFileAsync(Guid id); | Task DeleteFileAsync(Guid id); | ||||
| } | } | ||||
| } | } |
| public int[] TagsIds { get; set; } | public int[] TagsIds { get; set; } | ||||
| public IFormFile FileToUpload { get; set; } | public IFormFile FileToUpload { get; set; } | ||||
| public string Note { get; set; } | |||||
| public string? Note { get; set; } | |||||
| } | } | ||||
| } | } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Diligent.WebAPI.Contracts.DTOs.File | |||||
| { | |||||
| public class UpdateFileNoteRequest | |||||
| { | |||||
| public string Note { 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 Note { get; set; } | |||||
| public string Title { 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 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 Title { get; set; } | ||||
| public string? Note { 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 string File_stream { get; set; } | public string File_stream { get; set; } |
| public List<Tag> Tags { get; set; } | public List<Tag> Tags { get; set; } | ||||
| public bool Deleted { get; set; } = false; | public bool Deleted { get; set; } = false; | ||||
| public string? Note { get; set; } | |||||
| public string Note { get; set; } = ""; | |||||
| } | } | ||||
| } | } |
| using Microsoft.EntityFrameworkCore.Migrations; | |||||
| #nullable disable | |||||
| namespace Diligent.WebAPI.Data.Migrations | |||||
| { | |||||
| public partial class ChangedNoteInitialValueToEmptyString : Migration | |||||
| { | |||||
| protected override void Up(MigrationBuilder migrationBuilder) | |||||
| { | |||||
| migrationBuilder.AlterColumn<string>( | |||||
| name: "Note", | |||||
| table: "Files", | |||||
| type: "nvarchar(max)", | |||||
| nullable: false, | |||||
| defaultValue: "", | |||||
| oldClrType: typeof(string), | |||||
| oldType: "nvarchar(max)", | |||||
| oldNullable: true); | |||||
| } | |||||
| protected override void Down(MigrationBuilder migrationBuilder) | |||||
| { | |||||
| migrationBuilder.AlterColumn<string>( | |||||
| name: "Note", | |||||
| table: "Files", | |||||
| type: "nvarchar(max)", | |||||
| nullable: true, | |||||
| oldClrType: typeof(string), | |||||
| oldType: "nvarchar(max)"); | |||||
| } | |||||
| } | |||||
| } |
| .HasColumnType("uniqueidentifier"); | .HasColumnType("uniqueidentifier"); | ||||
| b.Property<string>("Note") | b.Property<string>("Note") | ||||
| .IsRequired() | |||||
| .HasColumnType("nvarchar(max)"); | .HasColumnType("nvarchar(max)"); | ||||
| b.Property<string>("Title") | b.Property<string>("Title") |
| return Ok(); | return Ok(); | ||||
| } | } | ||||
| [HttpPut("update-note/{id}")] | |||||
| public async Task<IActionResult> UpdateNote([FromBody]UpdateFileNoteRequest request, Guid id) | |||||
| { | |||||
| await _fileEntityService.UpdateNoteAsync(id, request); | |||||
| return Ok(); | |||||
| } | |||||
| [HttpDelete("delete-file/{id}")] | [HttpDelete("delete-file/{id}")] | ||||
| public async Task<IActionResult> DeleteFile([FromRoute]Guid id) | public async Task<IActionResult> DeleteFile([FromRoute]Guid id) | ||||
| { | { |