using System.Net.Http.Headers; using System.Text; using System.Text.Json; using IntegryApiClient.Core.Domain.RestClient.Contacts; using Microsoft.Extensions.Logging; using SteUp.Shared.Core.Dto; using SteUp.Shared.Core.Interface.IntegryApi; namespace SteUp.Shared.Core.Services; public class IntegryApiService( IIntegryApiRestClient integryApiRestClient, ILogger logger) : IIntegryApiService { public async Task SystemOk() { try { await integryApiRestClient.Get("system/ok"); return true; } catch (Exception e) { logger.LogError(e, e.Message); Console.WriteLine(e.Message); return false; } } public Task?> SuggestActivityDescription(string activityTypeId) => integryApiRestClient.AuthorizedGet?>("activity/suggestActivityDescription", new Dictionary { { "activityType", activityTypeId } } ); public async Task SendEmail(SendEmailDto sendEmail) { var content = new MultipartFormDataContent(); try { if (sendEmail.Attachments != null) { foreach (var a in sendEmail.Attachments) { var fileContent = new ByteArrayContent(a.FileContent); fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data"); content.Add(fileContent, "allegati", a.FileName); } } sendEmail.Attachments = null; content.Add( new StringContent( JsonSerializer.Serialize(sendEmail), Encoding.UTF8, "application/json" ), "request" ); await integryApiRestClient.AuthorizedPost("sendEmailNew", content); } catch (Exception e) { Console.WriteLine(e); logger.LogError(e, e.Message); throw; } finally { content.Dispose(); } } }