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; using TIAM.Services.Interfaces; using TIAM.Entities.Products; namespace TIAMWebApp.Server.Controllers { [ApiController] [Route("api/v1/[controller]")] public class TransferDataAPIController : ControllerBase, ITransferApiControllerCommon { private readonly AdminDal _adminDal; private readonly TIAM.Core.Loggers.ILogger _logger; private readonly TransferBackendService _transferBackendService; private readonly IMessageSenderService _messageSenderService; private readonly AuthService _authService; private readonly UserAPIController _userApiController; public TransferDataAPIController(AdminDal adminDal, TransferBackendService transferBackendService, IMessageSenderService messageSenderService, IEnumerable logWriters, AuthService authService, UserAPIController userApiController) { _adminDal = adminDal; _transferBackendService = transferBackendService; _logger = new TIAM.Core.Loggers.Logger(logWriters.ToArray()); _messageSenderService = messageSenderService; _authService = authService; _userApiController = userApiController; } [AllowAnonymous] [HttpGet] [Route(APIUrls.GetTransferDestinationsRouteName)] [SignalR(SignalRTags.GetAllTransferDestinations)] public List GetTransferDestinations() { return _adminDal.GetTransferDestinations(); } //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] [NonAction] [SignalR(SignalRTags.GetTransferDestinationById)] public async Task GetTransferDestinationById(Guid transferDestinationId) { var transferDestination = await _adminDal.GetTransferDestinationByIdAsync(transferDestinationId); return transferDestination; } [AllowAnonymous] [HttpGet] [Route("GetTransferDestinationByCoordinates")] public async Task 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 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 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 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)] [NonAction] [SignalR(SignalRTags.RemoveTransferDestination)] public async Task RemoveTransferDestination([FromBody] TransferDestination transferDestination) { var result = await _adminDal.RemoveTransferDestinationAsync(transferDestination, true); return result ? transferDestination : null; } //[AllowAnonymous] //[HttpPost] //[Route(APIUrls.CreateTransferDestinationRouteName)] //public async Task 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(); // 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 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(); // _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(); // //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> GetAllTransferDestinationToProducts() { return await _adminDal.GetTransferDestinationToProducts(); } [AllowAnonymous] [HttpGet] [Route(APIUrls.GetTransferDestinationToProductsByProductIdRouteName)] [SignalR(SignalRTags.GetTransferDestinationToProductsByProductId)] public async Task> GetTransferDestinationToProductsByProductId(Guid productId) { return await _adminDal.GetTransferDestinationToProductsByProductId(productId); } [AllowAnonymous] [HttpGet] [Route(APIUrls.GetTransferDestinationToProductsByTransferDestinationIdRouteName)] [SignalR(SignalRTags.GetTransferDestinationToProductsByTransferDestinationId)] public async Task> GetTransferDestinationToProductsByTransferDestinationId(Guid transferDestinationId) { return await _adminDal.GetTransferDestinationToProductsByTransferDestinationId(transferDestinationId); } //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDestinationToProductById)] [NonAction] [SignalR(SignalRTags.GetTransferDestinationToProductById)] public async Task GetTransferDestinationToProductById(Guid transferDestinationToProductId) { var transferDestination = await _adminDal.GetTransferDestinationToProductByIdAsync(transferDestinationToProductId); return transferDestination; } [AllowAnonymous] [HttpPost] [Route(APIUrls.CreateTransferDestinationToProductRouteName)] [SignalR(SignalRTags.CreateTransferDestinationToProduct)] public async Task 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 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 RemoveTransferDestinationToProduct([FromBody] TransferDestinationToProduct transferDestinationToProduct) { var result = await _adminDal.RemoveTransferDestinationToProductAsync(transferDestinationToProduct); return result ? transferDestinationToProduct : null; } //transfer [NonAction] [SignalR(SignalRTags.AddTransfer)] public async Task AddTransfer(Transfer transfer) { _logger.Info(@"CreateTransfer via SignalR called!"); 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 null; } 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 destList = _adminDal.GetTransferDestinations(); var from = destList.FirstOrDefault(x => x.AddressString == transfer.FromAddress); var to = destList.FirstOrDefault(x => x.AddressString == transfer.ToAddress); ////TODO //if (!transfer.ProductId.IsNullOrEmpty()) // transfer.Price = _transferBackendService.GetTransferPrice(transfer.ProductId.Value, from, to, transfer.PassengerCount); Product? product = null; //TODO if (!transfer.ProductId.IsNullOrEmpty()) { product = await _adminDal.GetProductByIdAsync((Guid)transfer.ProductId); transfer.Price = _transferBackendService.GetTransferPrice(transfer.ProductId.Value, from, to, transfer.PassengerCount); } transfer.TransferStatusType = TransferStatusType.OrderSubmitted; if (transfer.Price != null && transfer.Price > 0 && product != null) { if (product.ServiceProvider.CommissionPercent != null) { transfer.Revenue = transfer.Price * product.ServiceProvider.CommissionPercent / 100; } else { transfer.Revenue = 0; } } await _adminDal.AddTransferAsync(transfer); _logger.Info($"Created transfer, send emailMessage!!!"); var message = new MessageSenderModel(); message.Message = new 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 $@"

Dear {transfer.FullName},

We are pleased to inform you that a transfer order has been placed. Below are the details of the transfer:

{transfer.FromAddress} - {transfer.ToAddress}

{transfer.Appointment}

{transfer.FullName}

{transfer.PassengerCount}

Please confirm the transfer by clicking on the following link:

Confirm Transfer

If you did not request this transfer, please disregard this email.

Thank you,
Tour I Am team

"; } 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 transfer; } } else { return null; } } [AllowAnonymous] [HttpPost] [Route(APIUrls.CreateTransferRouteName)] public async Task 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(); 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); Product? product = null; //TODO if (!transfer.ProductId.IsNullOrEmpty()) { product = await _adminDal.GetProductByIdAsync((Guid)transfer.ProductId); transfer.Price = _transferBackendService.GetTransferPrice(transfer.ProductId.Value, from, to, transfer.PassengerCount); if (transfer.Price != null && transfer.Price > 0) { transfer.Revenue = _transferBackendService.GetCommission((Guid)transfer.ProductId, (double)transfer.Price, to); } else { transfer.Revenue = 0; } } transfer.TransferStatusType = TransferStatusType.OrderSubmitted; await _adminDal.AddTransferAsync(transfer); _logger.Info($"Created transfer, send emailMessage!!!"); var message = new MessageSenderModel(); 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 $@"

Dear {transfer.FullName},

We are pleased to inform you that a transfer order has been placed. Below are the details of the transfer:

{transfer.FromAddress} - {transfer.ToAddress}

{transfer.Appointment}

{transfer.FullName}

{transfer.PassengerCount}

Please confirm the transfer by clicking on the following link:

Confirm Transfer

If you did not request this transfer, please disregard this email.

Thank you,
Tour I Am team

"; } 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 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? transfers = JsonConvert.DeserializeObject>(serializedTransferList.GetRawText(), settings); //List? transfers = JObject.Parse(serializedTransferModel.GetRawText()).ToObject>(); List createdTransfers = new List(); 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(); 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 $@"

Dear {createdTransfer.FullName},

We are pleased to inform you that a transfer order has been placed. Below are the details of the transfer:

{createdTransfer.FromAddress} - {createdTransfer.ToAddress}

{createdTransfer.Appointment}

{createdTransfer.FullName}

{createdTransfer.PassengerCount}

Please confirm the transfer by clicking on the following link:

Confirm Transfer

If you did not request this transfer, please disregard this email.

Thank you,
Tour I Am team

"; } 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> GetTransfers() { _logger.Debug($"GetTransfers called;"); //var token = _authService.GetAuthTokenFromRequest(Request); //_logger.Detail(token); var result = await _adminDal.GetTransfersAsync(); return result; } [NonAction] [SignalR(SignalRTags.GetTransfersByFilterText)] public async Task> GetTransfersByFilterText(string criteriaOperatorText) { _logger.Debug($"GetTransfersByFilterText called; criteriaOperatorText: {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> GetTransfersByUserId(Guid userId) { _logger.Debug($"GetTransfersByUserId called; userId: {userId}"); var result = await _adminDal.GetTransfersByUserIdAsync(userId); return result; } [NonAction] [SignalR(SignalRTags.GetTransfersByOrderingProductId)] public async Task> GetTransfersByProductId(Guid productId) { _logger.Debug($"GetTransfersByProductId called; productId: {productId}"); var result = await _adminDal.GetTransfersByProductIdAsync(productId); return result; } [Authorize] [HttpGet] [Route(APIUrls.GetTransfersByUserProductMappingIdRouteName)] [SignalR(SignalRTags.GetTransfersByUserProductMappingId)] public async Task GetTransfersByDriverId(Guid userProductMappingId) { _logger.Debug($"GetTransferByDriverId called; userProductMappingId: {userProductMappingId}"); var result = await _adminDal.GetTransfersByUserProductMappingIdAsync(userProductMappingId); return result.ToJson(); } [AllowAnonymous] [HttpPost] [Route(APIUrls.GetTransferByIdRouteName)] [SignalR(SignalRTags.GetTransfer)] public async Task GetTransferById([FromBody] Guid transferId) { _logger.Debug($"GetTransferById called; transferId: {transferId}"); return await _adminDal.GetTransferByIdAsync(transferId); } [AllowAnonymous] [HttpPost] [Route(APIUrls.UpdateTransferRouteName)] [SignalR(SignalRTags.UpdateTransfer)] public async Task UpdateTransfer(Transfer transfer) { _logger.Info($"UpdateTransfer called! transferId: {transfer.Id}"); return await _adminDal.UpdateTransferAsync(transfer); } [AllowAnonymous] [HttpPost] [Route(APIUrls.GuestUpdateTransferRouteName)] [SignalR(SignalRTags.GuestUpdateTransfer)] public async Task GuestUpdateTransfer(Transfer transfer) { _logger.Info($"UpdateTransfer called! transferId: {transfer.Id}"); return await _adminDal.UpdateTransferAsync(transfer); } [AllowAnonymous] [HttpPost] [Route(APIUrls.DriverUpdateTransferRouteName)] [SignalR(SignalRTags.DriverUpdateTransfer)] public async Task DriverUpdateTransfer(Transfer transfer) { _logger.Info($"UpdateTransfer called! transferId: {transfer.Id}"); return await _adminDal.UpdateTransferAsync(transfer); } [NonAction] [SignalR(SignalRTags.RemoveTransfer)] public async Task RemoveTransfer(Transfer transfer) { _logger.Info($"RemoveTransfer called! transferId: {transfer.Id}"); var result = await _adminDal.RemoveTransferAsync(transfer); return result ? transfer : null; } //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriverRouteName)] [NonAction] [SignalR(SignalRTags.GetAllDrivers)] public async Task> GetAllDrivers() { _logger.Debug($"GetAllDrivers called!"); var result = await _adminDal.GetAllDriversAsync(); return result; } [NonAction] //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriverRouteName)] [SignalR(SignalRTags.GetAllDriversByProductId)] public async Task> GetAllDriversByProductId(Guid productId) { var result = await _adminDal.GetAllDriversByProductIdAsync(productId); return result; } [Authorize] [HttpGet] [Route(APIUrls.GetTransferDriverRouteName)] [SignalR(SignalRTags.GetTransferDriver)] public async Task GetTransferDriver(Guid transferDriverId) { _logger.Debug($"GetTransferDriver called; transferDriverId: {transferDriverId}"); var result = await _adminDal.GetTransferToDriverByIdAsync(transferDriverId); return result; } [Authorize] [HttpGet] [Route(APIUrls.GetTransferDriversByTransferIdRouteName)] [SignalR(SignalRTags.GetTransferDriversByTransferId)] public async Task> GetTransferDrivers(Guid transferId) { _logger.Debug($"GetTransferDrivers called; transferId: {transferId}"); var result = await _adminDal.GetTransferToDriversByTransferIdAsync(transferId); return result; } //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] [NonAction] [SignalR(SignalRTags.AddTransferToDriver)] public async Task AddTransferDriver([FromBody] TransferToDriver transferToDriver) { var result = await _adminDal.AddTransferToDriverAsync(transferToDriver); //TODO: Send email to driver... - J. //TODO: valamiért az AddTransferToDriverAsync nem tér vissza a Car-al és a UserProductMapping-el! - J. //return result ? transferToDriver : null; return result ? await _adminDal.GetTransferToDriverByIdAsync(transferToDriver.Id) : null; } //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] [NonAction] [SignalR(SignalRTags.UpdateTransferToDriver)] public async Task UpdateTransferDriver([FromBody] TransferToDriver transferToDriver) { var result = await _adminDal.UpdateTransferToDriverAsync(transferToDriver); //TODO: Send email to driver/user, ha van változás... - J. return result; // ? transferToDriver : null; } //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] [NonAction] [SignalR(SignalRTags.RemoveTransferToDriver)] public async Task RemoveTransferDriver([FromBody] TransferToDriver transferToDriver) { var result = await _adminDal.RemoveTransferToDriverAsync(transferToDriver); //TODO: Send email to driver/user... - J. return result ? transferToDriver : null; } } }