| 123456789101112131415161718192021222324252627282930313233 |
- using Dapper;
- using Diligent.WebAPI.Contracts.DTOs.Document;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Configuration;
- using System.Data.SqlClient;
- using static System.Net.Mime.MediaTypeNames;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class DocumentService : IDocumentService
- {
- private readonly IConfiguration _configuration;
-
- public DocumentService(IConfiguration configuration)
- {
- _configuration = configuration;
- }
- public async Task<DocumentReadDTO> UploadDocument(IFormFile file)
- {
- using var connection = new SqlConnection(_configuration.GetConnectionString("WebApi"));
- var ms = new MemoryStream();
- file.CopyTo(ms);
- var fileBytes = ms.ToArray();
- string fileName = string.Format(@"{0}" + $"{Path.GetExtension(file.FileName)}", DateTime.Now.Ticks);
- await connection.ExecuteAsync("insert into dbo.DocumentOrganizerDocStore (file_stream,name) values(@fileBytes,@fileName)",
- new { fileBytes = fileBytes, fileName = fileName });
-
- var fileByName = await connection.QueryFirstAsync<DocumentReadDTO>("select * from dbo.DocumentOrganizerDocStore where name=@fileName",
- new { fileName = fileName });
- return fileByName;
- }
- }
- }
|