using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks; using LCU.Shared.Common.NotificationApiLib.Models; using ReserveManagementSystemUI.Helpers; using Serilog; using LCU.Library.Internal.LcuHttpClient; namespace ReserveManagementSystemUI.Service { public class NotificationService { private ILcuHttpClient _lcuHttpClient; private IConfiguration _config; private ServiceHelpers _serviceHelper; public NotificationService(ILcuHttpClient lcuHttpClient, IConfiguration config, ServiceHelpers serviceHelper) { _lcuHttpClient = lcuHttpClient; _config = config; _serviceHelper = serviceHelper; } public async Task SendMessageAsync(string recipient) { List recipients = new List() { recipient }; string subject = "!Test!"; string body = "

This is a test notification sent from Blazor Base application!

"; var emailRequest = new EmailRequest { Recipient = recipients, Subject = subject, Body = body }; try { var apiUrl = _serviceHelper.GetControllerApiUrl("NotificationsUrl", "EmailController"); var encoded = JsonConvert.SerializeObject(emailRequest); var client = _lcuHttpClient.CreateClient(new Uri(apiUrl)); var content = new StringContent(encoded, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(apiUrl, content); response.EnsureSuccessStatusCode(); Log.Information("Emailer SendMessageAsync Method message sent"); return response.IsSuccessStatusCode; } catch (Exception ex) { Log.Error("Emailer SendMessageAsync Method: {0} {1}", ex.Message, ex.StackTrace); return false; } } } }