TourIAm/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs

704 lines
32 KiB
C#
Raw Blame History

using System.Linq.Expressions;
using System.Text.Json;
using AyCode.Core.Loggers;
using AyCode.Services.SignalRs;
using AyCode.Utils.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using TIAM.Core.Enums;
using TIAM.Database.DataLayers.Admins;
using TIAM.Entities.Emails;
using TIAM.Entities.Transfers;
using TIAM.Services;
using TIAM.Services.Server;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide.Messages;
using TIAMWebApp.Server.Services;
using TIAMWebApp.Shared.Application.Models.ClientSide;
using AyCode.Core.Extensions;
using TIAM.Entities.Users;
using TIAMSharedUI.Shared.Components.Grids;
using AyCode.Core.Helpers;
using System.Linq;
using DevExpress.Data.Filtering;
using DevExpress.Data.Linq;
using DevExpress.Data.Linq.Helpers;
using System;
using TIAM.Database.DbSets.Transfers;
namespace TIAMWebApp.Server.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class TransferDataAPIController : ControllerBase
{
private readonly AdminDal _adminDal;
private readonly TIAM.Core.Loggers.ILogger _logger;
private readonly TransferBackendService _transferBackendService;
private readonly IMessageSenderService _messageSenderService;
private readonly AuthService _authService;
public TransferDataAPIController(AdminDal adminDal, TransferBackendService transferBackendService, IMessageSenderService messageSenderService, IEnumerable<IAcLogWriterBase> logWriters, AuthService authService)
{
_adminDal = adminDal;
_transferBackendService = transferBackendService;
_logger = new TIAM.Core.Loggers.Logger<TransferDataAPIController>(logWriters.ToArray());
_messageSenderService = messageSenderService;
_authService = authService;
}
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetTransferDestinationsRouteName)]
[SignalR(SignalRTags.GetAllTransferDestinations)]
public List<TransferDestination> GetTransferDestinations()
{
return _adminDal.GetTransferDestinations();
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriversByTransferIdRouteName)]
[SignalR(SignalRTags.GetTransferDestinationById)]
public async Task<TransferDestination?> GetTransferDestinationById(Guid transferDestinationId)
{
var transferDestination = await _adminDal.GetTransferDestinationByIdAsync(transferDestinationId);
return transferDestination;
}
[AllowAnonymous]
[HttpGet]
[Route("GetTransferDestinationByCoordinates")]
public async Task<TransferDestination?> GetTransferDestinationByCoordinates(double latitude, double longitude)
{
return null;// await _transferDestinationDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.Latitude == latitude && x.Longitude == longitude);
}
[AllowAnonymous]
[HttpGet]
[Route("GetTransferDestinationByAddress")]
public async Task<TransferDestination?> GetTransferDestinationByAddress(string address)
{
return null;//await _transferDestinationDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.Address == address);
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.CreateTransferDestinationRouteName)]
[SignalR(SignalRTags.CreateTransferDestination)]
public async Task<TransferDestination?> CreateTransferDestination([FromBody] TransferDestination transferDestination)
{
_logger.Info(@"CreateTransferDestination called!");
var isSuccess = false;
if (string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
{
var logText = $"string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString); Name: {transferDestination.Name}; AddressString: {transferDestination.AddressString}";
_logger.Error(logText);
}
else
{
if (transferDestination.Id.IsNullOrEmpty()) transferDestination.Id = Guid.NewGuid();
isSuccess = await _adminDal.AddTransferDestinationAsync(transferDestination);
}
return isSuccess ? transferDestination : null;
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.UpdateTransferDestinationRouteName)]
[SignalR(SignalRTags.UpdateTransferDestination)]
public async Task<TransferDestination?> UpdateTransferDestination([FromBody] TransferDestination transferDestination)
{
_logger.Info(@"UpdateTransferDestination called!");
var isSuccess = false;
if (transferDestination.Id.IsNullOrEmpty() || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString))
{
var logText = $"transferDestination.Id.IsNullOrEmpty() || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString); Id: {transferDestination.Id}; Name: {transferDestination.Name}; AddressString: {transferDestination.AddressString}";
_logger.Error(logText);
}
else isSuccess = await _adminDal.UpdateTransferDestinationAsync(transferDestination);
return isSuccess ? transferDestination : null;
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriversByTransferIdRouteName)]
[SignalR(SignalRTags.RemoveTransferDestination)]
public async Task<TransferDestination?> RemoveTransferDestination([FromBody] TransferDestination transferDestination)
{
var result = await _adminDal.RemoveTransferDestinationAsync(transferDestination, true);
return result ? transferDestination : null;
}
//[AllowAnonymous]
//[HttpPost]
//[Route(APIUrls.CreateTransferDestinationRouteName)]
//public async Task<IActionResult> CreateTransferDestination([FromBody] JsonElement serializedTransferDestinationModel)
//{
// _logger.Info(@"CreateTransferDestination called!");
// if (string.IsNullOrEmpty(serializedTransferDestinationModel.GetRawText()))
// {
// return BadRequest("SerializedTramsferDestinationWizardModel is required");
// }
// else
// {
// TransferDestination? transferDestination = JObject.Parse(serializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>();
// 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))
// {
// return BadRequest("Invalid request");
// }
// else
// {
// _logger.Debug(transferDestination.ToString());
// //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
// await _adminDal.AddTransferDestinationAsync(transferDestination);
// return Ok(transferDestination);
// }
// }
// else
// {
// return BadRequest("Invalid request");
// }
// }
//}
//[AllowAnonymous]
//[HttpPost]
//[Route(APIUrls.UpdateTransferDestinationRouteName)]
//public async Task<IActionResult> UpdateTransferDestination([FromBody] JsonElement serializedTransferDestination)
//{
// _logger.Info(@"UpdateTransferDestination called!");
// if (string.IsNullOrEmpty(serializedTransferDestination.GetRawText()))
// {
// _logger.Error(@"Bad request!");
// return BadRequest("SerializedTramsferDestinationWizardModel is required");
// }
// else
// {
// _logger.Info(@"Serialized model not empty!");
// TransferDestination? transferDestination = JObject.Parse(serializedTransferDestination.GetRawText()).ToObject<TransferDestination>();
// _logger.Info($@"TransferDestination to be updated: {serializedTransferDestination.GetRawText()}");
// _logger.Info($@"TransferDestination to be updated: {transferDestination.AddressString}");
// 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))
// {
// _logger.Error(@"Serialized model not empty, but bad request!");
// return BadRequest("Invalid request");
// }
// else
// {
// _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}");
// _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}");
// //var dbTransferDestination = JObject.Parse(dbTransferDestinationJson).ToObject<TransferDestination>();
// //var dbTransferDestination = _adminDal.GetTransferDestinationById(transferDestination.Id, true);
// //if (dbTransferDestination.Id != Guid.Empty)
// //{
// // dbTransferDestination.AddressId = transferDestination.AddressId;
// // dbTransferDestination.Price = transferDestination.Price;
// // dbTransferDestination.PriceType = transferDestination.PriceType;
// // dbTransferDestination.Name = transferDestination.Name;
// // dbTransferDestination.Description = transferDestination.Description;
// // dbTransferDestination.AddressString = transferDestination.AddressString;
// // dbTransferDestination.Address = transferDestination.Address;
// //}
// //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
// await _adminDal.UpdateTransferDestinationAsync(transferDestination);
// return Ok(transferDestination);
// }
// }
// else
// {
// return BadRequest("Invalid request");
// }
// }
//}
//TransferDestinationToProduct
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetAllTransferDestinationToProductsRouteName)]
[SignalR(SignalRTags.GetAllTransferDestinationToProducts)]
public async Task<List<TransferDestinationToProduct>> GetAllTransferDestinationToProducts()
{
return await _adminDal.GetTransferDestinationToProducts();
}
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetTransferDestinationToProductsByProductIdRouteName)]
[SignalR(SignalRTags.GetTransferDestinationToProductsByProductId)]
public async Task<List<TransferDestinationToProduct>> GetTransferDestinationToProductsByProductId(Guid productId)
{
return await _adminDal.GetTransferDestinationToProductsByProductId(productId);
}
[AllowAnonymous]
[HttpGet]
[Route(APIUrls.GetTransferDestinationToProductsByTransferDestinationIdRouteName)]
[SignalR(SignalRTags.GetTransferDestinationToProductsByTransferDestinationId)]
public async Task<List<TransferDestinationToProduct>> GetTransferDestinationToProductsByTransferDestinationId(Guid transferDestinationId)
{
return await _adminDal.GetTransferDestinationToProductsByTransferDestinationId(transferDestinationId);
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDestinationToProductById)]
[NonAction]
[SignalR(SignalRTags.GetTransferDestinationToProductById)]
public async Task<TransferDestinationToProduct?> GetTransferDestinationToProductById(Guid transferDestinationToProductId)
{
var transferDestination = await _adminDal.GetTransferDestinationToProductByIdAsync(transferDestinationToProductId);
return transferDestination;
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.CreateTransferDestinationToProductRouteName)]
[SignalR(SignalRTags.CreateTransferDestinationToProduct)]
public async Task<TransferDestinationToProduct?> CreateTransferDestinationToProduct([FromBody] TransferDestinationToProduct transferDestinationToProduct)
{
_logger.Info(@"CreateTransferDestination called!");
var isSuccess = false;
if (transferDestinationToProduct.ProductId.IsNullOrEmpty() || transferDestinationToProduct.TransferDestinationId.IsNullOrEmpty())
{
var logText = $"transferDestinationToProduct.ProductId.IsNullOrEmpty() || transferDestinationToProduct.TransferDestinationId.IsNullOrEmpty(); ProductId: {transferDestinationToProduct.ProductId}; TransferDestinationId: {transferDestinationToProduct.TransferDestinationId}";
_logger.Error(logText);
}
else
{
if (transferDestinationToProduct.Id.IsNullOrEmpty()) transferDestinationToProduct.Id = Guid.NewGuid();
isSuccess = await _adminDal.AddTransferDestinationToProductAsync(transferDestinationToProduct);
}
return isSuccess ? transferDestinationToProduct : null;
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.UpdateTransferDestinationToProductRouteName)]
[SignalR(SignalRTags.UpdateTransferDestinationToProduct)]
public async Task<TransferDestinationToProduct?> UpdateTransferDestinationToProduct([FromBody] TransferDestinationToProduct transferDestinationToProduct)
{
_logger.Info(@"UpdateTransferDestination called!");
var isSuccess = false;
if (transferDestinationToProduct.Id.IsNullOrEmpty() || transferDestinationToProduct.ProductId.IsNullOrEmpty() || transferDestinationToProduct.TransferDestinationId.IsNullOrEmpty())
{
var logText = $"transferDestinationToProduct.Id.IsNullOrEmpty() || transferDestinationToProduct.ProductId.IsNullOrEmpty() || transferDestinationToProduct.TransferDestinationId.IsNullOrEmpty(); Id: {transferDestinationToProduct.Id}; ProductId: {transferDestinationToProduct.ProductId}; TransferDestinationId: {transferDestinationToProduct.TransferDestinationId}";
_logger.Error(logText);
}
else isSuccess = await _adminDal.UpdateTransferDestinationToProductAsync(transferDestinationToProduct);
return isSuccess ? transferDestinationToProduct : null;
}
[Authorize]
[HttpGet]
[Route(APIUrls.RemoveTransferDestinationToProductRouteName)]
[SignalR(SignalRTags.RemoveTransferDestinationToProduct)]
public async Task<TransferDestinationToProduct?> RemoveTransferDestinationToProduct([FromBody] TransferDestinationToProduct transferDestinationToProduct)
{
var result = await _adminDal.RemoveTransferDestinationToProductAsync(transferDestinationToProduct);
return result ? transferDestinationToProduct : null;
}
//transfer
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.CreateTransferRouteName)]
public async Task<IActionResult> CreateTransfer([FromBody] JsonElement serializedTransferModel)
{
_logger.Info(@"CreateTransfer called!");
if (string.IsNullOrEmpty(serializedTransferModel.GetRawText()))
{
return BadRequest("SerializedTramsferDestinationWizardModel is required");
}
else
{
Transfer? transfer = JObject.Parse(serializedTransferModel.GetRawText()).ToObject<Transfer>();
if (transfer != null)
{
var id = Guid.NewGuid();
//TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
if (string.IsNullOrEmpty(transfer.FromAddress) || string.IsNullOrEmpty(transfer.ToAddress))
{
return BadRequest("Invalid request");
}
else
{
_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())
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.Id = Guid.NewGuid();
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=""{Setting.BaseUrl}/mytransfers/{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);
await _adminDal.AddEmailMessageAsync(messageElement);
_logger.Info("SendEmail result: " + result);
return Ok(transfer);
}
}
else
{
return BadRequest("Invalid request");
}
}
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.CreateTransfersRouteName)]
public async Task<IActionResult> CreateTransfers([FromBody] JsonElement serializedTransferList)
{
_logger.Info(@"CreateTransfers called!");
if (string.IsNullOrEmpty(serializedTransferList.GetRawText()))
{
return BadRequest("SerializedTramsferDestinationWizardModel is required");
}
else
{
_logger.Info($@"Serialized model: {serializedTransferList.GetRawText()}");
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
List<Transfer>? transfers = JsonConvert.DeserializeObject<List<Transfer>>(serializedTransferList.GetRawText(), settings);
//List<Transfer>? transfers = JObject.Parse(serializedTransferModel.GetRawText()).ToObject<List<Transfer>>();
List<Transfer> createdTransfers = new List<Transfer>();
if (transfers != null)
{
foreach (var transfer in transfers)
{
var id = Guid.NewGuid();
var result = await _adminDal.AddTransferAsync(transfer);
if (result)
{
createdTransfers.Add(transfer);
}
}
foreach (var createdTransfer in createdTransfers)
{
_logger.Info($"Created transfer, send emailMessage!!!");
var message = new MessageSenderModel<EmailMessage>();
message.Message = new EmailMessage();
message.Message.Id = Guid.NewGuid();
message.MessageType = AyCode.Models.Enums.MessageTypesEnum.email;
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=""{Setting.BaseUrl}/mytransfers/{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);
await _adminDal.AddEmailMessageAsync(messageElement);
_logger.Info("SendEmail result: " + result);
}
return Ok(createdTransfers);
}
else
{
return BadRequest("Invalid request");
}
}
}
[Authorize]
[HttpGet]
[Route(APIUrls.GetTransfersRouteName)]
[SignalR(SignalRTags.GetTransfers)]
public async Task<List<Transfer>> GetTransfers()
{
//var token = _authService.GetAuthTokenFromRequest(Request);
//_logger.Detail(token);
var result = await _adminDal.GetTransfersAsync();
return result;
}
[NonAction]
[SignalR(SignalRTags.GetTransfersByFilterText)]
public async Task<List<Transfer>> GetTransfersByFilterText(string criteriaOperatorText)
{
if (criteriaOperatorText.IsNullOrWhiteSpace()) return await GetTransfers();
var results = await _adminDal.GetTransfersByFilterAsync(CriteriaOperator.Parse(criteriaOperatorText));
return results;
}
[Authorize]
[HttpGet]
[Route(APIUrls.GetTransfersByUserIdRouteName)]
[SignalR(SignalRTags.GetTransfersByUserId)]
public async Task<string> GetTransfersByUserId(Guid userId)
{
var result = await _adminDal.GetTransfersByUserIdJsonAsync(userId);
return result;
}
[Authorize]
[HttpGet]
[Route(APIUrls.GetTransfersByUserProductMappingIdRouteName)]
[SignalR(SignalRTags.GetTransfersByUserProductMappingId)]
public async Task<string> GetTransfersByDriverId(Guid userProductMappingId)
{
_logger.Debug($"GetTransferByDriverId called!!!");
var result = await _adminDal.GetTransfersByUserProductMappingIdAsync(userProductMappingId);
return result.ToJson();
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetTransferByIdRouteName)]
[SignalR(SignalRTags.GetTransfer)]
public string? GetTransferById([FromBody] Guid transferId)
{
_logger.Info($"Get transfer by id called; transferId: {transferId}");
return _adminDal.GetTransferJsonById(transferId);
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.UpdateTransferRouteName)]
[SignalR(SignalRTags.UpdateTransfer)]
public async Task<Transfer?> UpdateTransfer(Transfer transfer)
{
_logger.Info($"UpdateTransfer called! + {transfer.Id}");
return await _adminDal.UpdateTransferAsync(transfer);
}
[NonAction]
[SignalR(SignalRTags.RemoveTransfer)]
public async Task<Transfer?> RemoveTransfer(Transfer transfer)
{
_logger.Info($"RemoveTransfer called! + {transfer.Id}");
var result = await _adminDal.RemoveTransferAsync(transfer);
return result ? transfer : null;
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriverRouteName)]
[NonAction]
[SignalR(SignalRTags.GetAllDrivers)]
public async Task<List<UserProductMapping>> GetAllDrivers()
{
var result = await _adminDal.GetAllDriversAsync();
return result;
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriverRouteName)]
[SignalR(SignalRTags.GetAllDriversByProductId)]
public async Task<List<UserProductMapping>> GetAllDriversByProductId(Guid productId)
{
var result = await _adminDal.GetAllDriversByProductIdAsync(productId);
return result;
}
[Authorize]
[HttpGet]
[Route(APIUrls.GetTransferDriverRouteName)]
[SignalR(SignalRTags.GetTransferDriver)]
public async Task<TransferToDriver?> GetTransferDriver(Guid transferDriverId)
{
var result = await _adminDal.GetTransferToDriverByIdAsync(transferDriverId);
return result;
}
[Authorize]
[HttpGet]
[Route(APIUrls.GetTransferDriversByTransferIdRouteName)]
[SignalR(SignalRTags.GetTransferDriversByTransferId)]
public async Task<List<TransferToDriver>> GetTransferDrivers(Guid transferId)
{
var result = await _adminDal.GetTransferToDriversByTransferIdAsync(transferId);
return result;
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriversByTransferIdRouteName)]
[NonAction]
[SignalR(SignalRTags.AddTransferToDriver)]
public async Task<TransferToDriver?> AddTransferDriver([FromBody] TransferToDriver transferToDriver)
{
var result = await _adminDal.AddTransferToDriverAsync(transferToDriver);
//TODO: Send email to driver... - J.
return result ? transferToDriver : null;
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriversByTransferIdRouteName)]
[NonAction]
[SignalR(SignalRTags.UpdateTransferToDriver)]
public async Task<TransferToDriver?> UpdateTransferDriver([FromBody] TransferToDriver transferToDriver)
{
var result = await _adminDal.UpdateTransferToDriverAsync(transferToDriver);
//TODO: Send email to driver/user, ha van v<>ltoz<6F>s... - J.
return result; // ? transferToDriver : null;
}
//[Authorize]
//[HttpGet]
//[Route(APIUrls.GetTransferDriversByTransferIdRouteName)]
[NonAction]
[SignalR(SignalRTags.RemoveTransferToDriver)]
public async Task<TransferToDriver?> RemoveTransferDriver([FromBody] TransferToDriver transferToDriver)
{
var result = await _adminDal.RemoveTransferToDriverAsync(transferToDriver);
//TODO: Send email to driver/user... - J.
return result ? transferToDriver : null;
}
}
}