Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DocumentService.cs 1.3KB

123456789101112131415161718192021222324252627282930313233
  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. using static System.Net.Mime.MediaTypeNames;
  7. namespace Diligent.WebAPI.Business.Services
  8. {
  9. public class DocumentService : IDocumentService
  10. {
  11. private readonly IConfiguration _configuration;
  12. public DocumentService(IConfiguration configuration)
  13. {
  14. _configuration = configuration;
  15. }
  16. public async Task<DocumentReadDTO> UploadDocument(IFormFile file)
  17. {
  18. using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
  19. var ms = new MemoryStream();
  20. file.CopyTo(ms);
  21. var fileBytes = ms.ToArray();
  22. string fileName = string.Format(@"{0}" + $"{Path.GetExtension(file.FileName)}", DateTime.Now.Ticks);
  23. await connection.ExecuteAsync("insert into dbo.DocumentOrganizerDocStore (file_stream,name) values(@fileBytes,@fileName)",
  24. new { fileBytes = fileBytes, fileName = fileName });
  25. var fileByName = await connection.QueryFirstAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore where name=@fileName",
  26. new { fileName = fileName });
  27. return fileByName;
  28. }
  29. }
  30. }