Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

DocumentService.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Dapper;
  2. using Diligent.WebAPI.Contracts.DTOs.Document;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.Extensions.Configuration;
  5. using System.Data.SqlClient;
  6. namespace Diligent.WebAPI.Business.Services
  7. {
  8. public class DocumentService : IDocumentService
  9. {
  10. private readonly IConfiguration _configuration;
  11. public DocumentService(IConfiguration configuration)
  12. {
  13. _configuration = configuration;
  14. }
  15. public async Task<List<DocumentReadDTO>> GetAllDocuments()
  16. {
  17. using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
  18. var files = await connection.QueryAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore");
  19. return files.ToList();
  20. }
  21. public async Task<List<DocumentReadDTO>> GetDocumentsByText(string text)
  22. {
  23. using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
  24. var files = await connection.QueryAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore where contains(file_stream, @text)",
  25. new { text = text });
  26. return files.ToList();
  27. }
  28. public async Task UploadDocument(IFormFile file)
  29. {
  30. using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
  31. var ms = new MemoryStream();
  32. file.CopyTo(ms);
  33. var fileBytes = ms.ToArray();
  34. await connection.ExecuteAsync("insert into dbo.DocumentOrganizerDocStore (file_stream,name) values(@fileBytes,'neki2.txt')",
  35. new { fileBytes = fileBytes });
  36. }
  37. }
  38. }