| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using Dapper;
- using Diligent.WebAPI.Contracts.DTOs.Document;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Configuration;
- using System.Data.SqlClient;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class DocumentService : IDocumentService
- {
- private readonly IConfiguration _configuration;
-
- public DocumentService(IConfiguration configuration)
- {
- _configuration = configuration;
- }
- public async Task<List<DocumentReadDTO>> GetAllDocuments()
- {
- using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
- var files = await connection.QueryAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore");
- return files.ToList();
- }
-
- public async Task<List<DocumentReadDTO>> GetDocumentsByText(string text)
- {
- using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
- var files = await connection.QueryAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore where contains(file_stream, @text)",
- new { text = text });
- return files.ToList();
- }
-
- public async Task UploadDocument(IFormFile file)
- {
- using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
- var ms = new MemoryStream();
- file.CopyTo(ms);
- var fileBytes = ms.ToArray();
- await connection.ExecuteAsync("insert into dbo.DocumentOrganizerDocStore (file_stream,name) values(@fileBytes,'neki2.txt')",
- new { fileBytes = fileBytes });
- }
- }
- }
|