This commit is contained in:
jozsef.b@aycode.com 2024-05-18 13:14:45 +02:00
commit 876a525342
10 changed files with 188 additions and 40 deletions

View File

@ -60,26 +60,66 @@ namespace TIAM.Services.Server
if (message.SenderId == Guid.Empty)
{
from = new EmailAddress("noreply@tiam.com", "TourIAm mailservice");
from = new EmailAddress("noreply@touriam.com", "TourIAm mailservice");
}
else
{
from = new EmailAddress(message.EmailAddress, senderUser.Profile.Name);
}
List<Task<Response>> sendTasks = new List<Task<Response>>();
foreach (var messageRecipient in message.Recipients)
{
var to = new EmailAddress(messageRecipient.EmailAddress, messageRecipient.EmailAddress);
var plainTextContent = message.Text;
//var _htmlContent = message.;
//MailHelper.CreateSingleEmailToMultipleRecipients()
var msg = MailHelper.CreateSingleEmail(from, to, message.Subject, plainTextContent, plainTextContent);
var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
sendTasks.Add(client.SendEmailAsync(msg));
}
//return response.StatusCode;
return HttpStatusCode.Accepted;
var responses = await Task.WhenAll(sendTasks).ConfigureAwait(false);
if (responses.Any(response => !response.IsSuccessStatusCode))
{
Console.WriteLine("Some emails failed to send");
return HttpStatusCode.InternalServerError;
}
Console.WriteLine("All emails sent successfully");
return HttpStatusCode.OK;
//List<bool> results = new List<bool>();
//foreach (var messageRecipient in message.Recipients)
//{
// var to = new EmailAddress(messageRecipient.EmailAddress, messageRecipient.EmailAddress);
// var plainTextContent = message.Text;
// //var _htmlContent = message.;
// //MailHelper.CreateSingleEmailToMultipleRecipients()
// var msg = MailHelper.CreateSingleEmail(from, to, message.Subject, plainTextContent, plainTextContent);
// var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
// if(response.IsSuccessStatusCode)
// {
// results.Add(true);
// }
// else { results.Add(false); }
//}
//if(results.Any(x => x=false))
//{
// return HttpStatusCode.BadRequest;
//}
//else
//{
// return HttpStatusCode.OK;
//}
////return response.StatusCode;
}
}

View File

@ -2,7 +2,7 @@
@using System.ComponentModel.DataAnnotations
@using BlazorAnimation
<Animation Effect="@Effect.FadeInUp" Speed="@Speed.Fast" Delay="@TimeSpan.FromMilliseconds(250)">
@* <Animation Effect="@Effect.FadeInUp" Speed="@Speed.Fast" Delay="@TimeSpan.FromMilliseconds(250)"> *@
<EditForm Model="@Data"
OnValidSubmit="@HandleValidSubmit"
@ -24,7 +24,7 @@
<p class="mt-2 cw-480">
@_formSubmitResult
</p>
</Animation>
@* </Animation> *@
@code {

View File

@ -367,7 +367,7 @@ namespace TIAMSharedUI.Pages.Components
_logger.Detail($"Slider changed to {result}");
property.SetValue(Data, result);
_logger.Detail($"bleh: {property.Name} = {property.GetValue(Data)}");
StateHasChanged(); // Add this line to refresh the UI
//StateHasChanged(); // Add this line to refresh the UI
}));
editor.CloseComponent();

View File

@ -22,6 +22,7 @@
@inject IStringLocalizer<TIAMResources> localizer
@inject IWizardProcessor wizardProcessor
@inject ITransferDataService transferDataService
@inject ISessionService sessionService
<PageTitle>Transfers</PageTitle>
<div class="text-center m-5">
@ -45,7 +46,7 @@
IgnoreReflection=@ignoreList
TitleResourceString="NewMessage"
SubtitleResourceString="NewMessageSubtitle"
SubmitButtonText="ButtonSend"></InputWizard>
SubmitButtonText="@localizer.GetString("ButtonSend")"></InputWizard>
</BodyContentTemplate>
<FooterContentTemplate Context="Context">
<div class="popup-demo-events-footer">
@ -210,6 +211,7 @@
"ReceiverEmailAddress",
"ReceiverId",
"SenderEmailAddress",
"SenderFullName",
"SenderId",
"ContextId"
};
@ -226,7 +228,15 @@
void SendMail(Transfer Item)
{
_logger.Info($"Sending mail to {Item.ContactEmail}");
_logger.Info($"Sending mail to {Item.ContactEmail}, {Item.Id}");
Guid? nullableGuid = Item.Id;
if (nullableGuid.HasValue)
{
Guid nonNullableGuid = nullableGuid.Value;
messageWizardModel.ContextId = nonNullableGuid;
}
messageWizardModel.SenderFullName = Item.FullName;
PopupVisible = true;
}
@ -251,7 +261,25 @@
public async Task SubmitForm(object Result)
{
var email = await wizardProcessor.ProcessWizardAsync<MessageWizardModel>(Result.GetType(), Result);
var messageModel = Result as MessageWizardModel;
messageModel.ContextId = messageWizardModel.ContextId;
//messageModel.SenderId = sessionService.User.UserId;
string FormatEmailContent()
{
return $@"
<html>
<body>
<p>Dear {messageModel.SenderFullName},</p>
<p>{messageModel.Content}:</p>
<p>Best regards,<br/>Tour I Am team</p>
</body>
</html>";
}
messageModel.Content = FormatEmailContent();
_logger.Info(messageModel.Content);
var email = await wizardProcessor.ProcessWizardAsync<MessageWizardModel>(Result.GetType(), messageModel);
_logger.Info($"Submitted nested form: {Result.GetType().FullName}");
}

View File

@ -39,11 +39,11 @@ namespace TIAMSharedUI.Shared.Components
private bool enableLogin = false;
private bool enableLogin = true;
private bool enableEvents = false;
private bool enableTransfer = true;
private bool enableLanguage = false;
private bool enableApi = false;
private bool enableApi = true;

View File

@ -45,6 +45,9 @@
<Reference Include="AyCode.Services">
<HintPath>..\..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Services.dll</HintPath>
</Reference>
<Reference Include="AyCode.Utils">
<HintPath>..\..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Utils.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@ -36,6 +36,7 @@ namespace TIAMWebApp.Server.Controllers
private readonly AdminDal _adminDal;
private readonly TIAM.Core.Loggers.ILogger _logger;
private readonly TransferBackendService _transferBackendService;
private readonly IMessageSenderService _messageSenderService;
public TransferDataAPIController(AdminDal adminDal, TransferBackendService transferBackendService, IEnumerable<IAcLogWriterBase> logWriters)
{
@ -43,9 +44,10 @@ namespace TIAMWebApp.Server.Controllers
_transferBackendService = transferBackendService;
_logger = new TIAM.Core.Loggers.Logger<TransferDataAPIController>(logWriters.ToArray());
_messageSenderService = messageSenderService;
}
[AllowAnonymous]
[HttpGet]
@ -87,10 +89,10 @@ namespace TIAMWebApp.Server.Controllers
if (transferDestination != null)
{
var id = Guid.NewGuid();
//TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
if (string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
{
@ -109,7 +111,7 @@ namespace TIAMWebApp.Server.Controllers
{
return BadRequest("Invalid request");
}
}
@ -119,7 +121,7 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.UpdateTransferDestinationRouteName)]
public async Task<IActionResult> UpdateTransferDestination([FromBody]JsonElement serializedTransferDestination)
public async Task<IActionResult> UpdateTransferDestination([FromBody] JsonElement serializedTransferDestination)
{
_logger.Info(@"UpdateTransferDestination called!");
if (string.IsNullOrEmpty(serializedTransferDestination.GetRawText()))
@ -138,7 +140,7 @@ namespace TIAMWebApp.Server.Controllers
if (transferDestination != null)
{
//TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
if (transferDestination.Id == Guid.Empty || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
@ -149,14 +151,14 @@ namespace TIAMWebApp.Server.Controllers
else
{
Console.WriteLine($@"TransferDestination to be updated: {transferDestination.Id}");
Console.WriteLine($@"TransferDestination to be updated new name: {transferDestination.Name}");
Console.WriteLine($@"TransferDestination to be updated new price: {transferDestination.Price}");
_logger.Info($@"TransferDestination to be updated: {transferDestination.Id}");
_logger.Info($@"TransferDestination to be updated new name: {transferDestination.Name}");
_logger.Info($@"TransferDestination to be updated new price: {transferDestination.Price}");
//Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price2}");
//Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price3}");
//Console.WriteLine($"TransferDestination to be updated new priceType: {transferDestination.PriceType}");
Console.WriteLine($@"TransferDestination to be updated new address: {transferDestination.AddressString}");
Console.WriteLine($@"TransferDestination to be updated new description: {transferDestination.Description}");
_logger.Info($@"TransferDestination to be updated new address: {transferDestination.AddressString}");
_logger.Info($@"TransferDestination to be updated new description: {transferDestination.Description}");
//var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id);
//_logger.Info($"TransferDestination JSON to be updated: {dbTransferDestinationJson}");
@ -173,7 +175,7 @@ namespace TIAMWebApp.Server.Controllers
// dbTransferDestination.Description = transferDestination.Description;
// dbTransferDestination.AddressString = transferDestination.AddressString;
// dbTransferDestination.Address = transferDestination.Address;
//}
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
@ -204,7 +206,7 @@ namespace TIAMWebApp.Server.Controllers
}
else
{
Transfer? transfer= JObject.Parse(serializedTransferModel.GetRawText()).ToObject<Transfer>();
Transfer? transfer = JObject.Parse(serializedTransferModel.GetRawText()).ToObject<Transfer>();
if (transfer != null)
{
@ -219,22 +221,58 @@ namespace TIAMWebApp.Server.Controllers
}
else
{
Console.WriteLine($@"TransferDestination to be created: {id}");
Console.WriteLine($@"TransferDestination to be created: {transfer.FromAddress}");
Console.WriteLine($@"TransferDestination to be created: {transfer.ToAddress}");
Console.WriteLine($@"TransferDestination to be created: {transfer.ProductId}");
Console.WriteLine($@"TransferDestination to be created: {transfer.Price}");
_logger.Info($@"TransferDestination to be created: {id}");
_logger.Info($@"TransferDestination to be created: {transfer.FromAddress}");
_logger.Info($@"TransferDestination to be created: {transfer.ToAddress}");
_logger.Info($@"TransferDestination to be created: {transfer.ProductId}");
_logger.Info($@"TransferDestination to be created: {transfer.Price}");
var from = await _adminDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.AddressString == transfer.FromAddress);
var to = await _adminDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.AddressString == transfer.ToAddress);
//TODO
if(!transfer.ProductId.IsNullOrEmpty())
if (!transfer.ProductId.IsNullOrEmpty())
transfer.Price = _transferBackendService.GetTransferPrice(transfer.ProductId.Value, from, to, transfer.PassengerCount);
transfer.TransferStatusType = TransferStatusType.OrderSubmitted;
await _adminDal.AddTransferAsync(transfer);
_logger.Info($"Created transfer, send emailMessage!!!");
var message = new MessageSenderModel<EmailMessage>();
message.Message.Subject = "[Tour I Am] New transfer in Budapest";
message.Message.ContextId = transfer.Id;
message.Message.SenderId = Guid.Empty;
message.Message.Recipients.Add(new EmailRecipient(Guid.NewGuid(), transfer.UserId, Guid.NewGuid(), transfer.ContactEmail));
string FormatEmailContent()
{
return $@"
<html>
<body>
<p>Dear {transfer.FullName},</p>
<p>We are pleased to inform you that a transfer order has been placed. Below are the details of the transfer:</p>
<p>{transfer.FromAddress} - {transfer.ToAddress}</p>
<p>{transfer.Appointment}</p>
<p>{transfer.FullName}</p>
<p>{transfer.PassengerCount}</p>
<p>Please confirm the transfer by clicking on the following link:</p>
<p><a href=""https://www.touriam.com/mytransfer?{transfer.Id}"">Confirm Transfer</a></p>
<p>If you did not request this transfer, please disregard this email.</p>
<p>Thank you,<br/>Tour I Am team</p>
</body>
</html>";
}
message.Message.Text = FormatEmailContent();
_logger.Info(message.Message.Text);
//message.Message.Text = $"Dear {transfer.FullName}! /n We have received an order from you, please confirm the details here: https://www.touriam.com/mytransfer?{transfer.Id}";
var messageElement = message.Message;
var result = await _messageSenderService.SendMessageAsync(messageElement, (int)message.MessageType);
//_adminDal.AddEmailMessageAsync((TIAM.Entities.Emails.EmailMessage)SerializedMessageSenderModel.Message);
_logger.Info("SendEmail result: " + result);
return Ok(transfer);
}
}
@ -278,11 +316,48 @@ namespace TIAMWebApp.Server.Controllers
{
var id = Guid.NewGuid();
var result = await _adminDal.AddTransferAsync(transfer);
if(result)
if (result)
{
createdTransfers.Add(transfer);
}
}
foreach (var createdTransfer in createdTransfers)
{
_logger.Info($"Created transfer, send emailMessage!!!");
var message = new MessageSenderModel<EmailMessage>();
message.Message.Subject = "[Tour I Am] New transfer in Budapest";
message.Message.ContextId = createdTransfer.Id;
message.Message.SenderId = Guid.Empty;
message.Message.Recipients.Add(new EmailRecipient(Guid.NewGuid(), createdTransfer.UserId, Guid.NewGuid(), createdTransfer.ContactEmail));
string FormatEmailContent()
{
return $@"
<html>
<body>
<p>Dear {createdTransfer.FullName},</p>
<p>We are pleased to inform you that a transfer order has been placed. Below are the details of the transfer:</p>
<p>
{createdTransfer.FromAddress} - {createdTransfer.ToAddress}</p>
<p>{createdTransfer.Appointment}</p>
<p>{createdTransfer.FullName}</p>
<p>{createdTransfer.PassengerCount}</p>
<p>Please confirm the transfer by clicking on the following link:</p>
<p><a href=""https://www.touriam.com/mytransfer?{createdTransfer.Id}"">Confirm Transfer</a></p>
<p>If you did not request this transfer, please disregard this email.</p>
<p>Thank you,<br/>Tour I Am team</p>
</body>
</html>";
}
message.Message.Text = FormatEmailContent();
_logger.Info(message.Message.Text);
var messageElement = message.Message;
Console.WriteLine(message.Message);
var result = await _messageSenderService.SendMessageAsync(messageElement, (int)message.MessageType);
//_adminDal.AddEmailMessageAsync((TIAM.Entities.Emails.EmailMessage)SerializedMessageSenderModel.Message);
_logger.Info("SendEmail result: " + result);
}
return Ok(createdTransfers);
}
else
@ -299,7 +374,7 @@ namespace TIAMWebApp.Server.Controllers
{
var result = await _adminDal.GetTransfersJsonAsync();
return result;
return result;
}

View File

@ -38,6 +38,7 @@ builder.Services.AddScoped<AdminDal>();
builder.Services.AddScoped<AuctionDal>();
builder.Services.AddScoped<TransferDestinationDal>();
builder.Services.AddCors(options => {
options.AddPolicy(myAllowSpecificOrigins,
policy => {

View File

@ -17,6 +17,7 @@ namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
public string ReceiverEmailAddress { get; set; }
public Guid ReceiverId { get; set; }
public string SenderEmailAddress { get; set; }
public string SenderFullName { get; set; }
public Guid SenderId { get; set; }
public Guid ContextId { get; set; }
[Required(ErrorMessage = "The subject value should be specified.")]

View File

@ -47,8 +47,8 @@ namespace TIAMWebApp.Shared.Application.Services
if (!response.IsSuccessStatusCode)
return null;
var result = (string)(await response.Content.ReadFromJsonAsync(typeof(string)));
return result;
var result = (HttpResponseMessage)(await response.Content.ReadFromJsonAsync(typeof(HttpResponseMessage)));
return result.Content.ToString();
}