128 lines
6.6 KiB
C#
128 lines
6.6 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Reflection.Metadata;
|
|
using System.Text.Json;
|
|
using TIAM.Database.DataLayers;
|
|
using TIAM.Database.DataLayers.Admins;
|
|
using TIAM.Database.DataLayers.TransferDestinations;
|
|
using TIAM.Database.DataLayers.Users;
|
|
using TIAM.Database.DbContexts;
|
|
using TIAM.Entities.TransferDestinations;
|
|
using TIAM.Entities.Users;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
|
|
using TIAMWebApp.Shared.Application.Models.PageModels;
|
|
|
|
namespace TIAMWebApp.Server.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class TransferDataAPIController : ControllerBase
|
|
{
|
|
//private static readonly TransferDestination[] Names = new TransferDestination[]
|
|
//{
|
|
// /*"Castle of Buda", "Hungarian National Museum", "Parliament of Hungary", "Heroes square", "Gellert Hill", "Margaret Island"*/
|
|
// new() { DestinationId = 1, DestinationName = "Airport", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f },
|
|
// new() { DestinationId = 2, DestinationName = "Castle of Buda", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f },
|
|
// new() { DestinationId = 3, DestinationName = "Hungarian National Museum", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f },
|
|
// new() { DestinationId = 4, DestinationName = "Parliament of Hungary", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f },
|
|
// new() { DestinationId = 5, DestinationName = "Heroes square", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f },
|
|
// new() { DestinationId = 6, DestinationName = "Gellert Hill", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f },
|
|
// new() { DestinationId = 6, DestinationName = "Margaret Island", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }
|
|
|
|
//};
|
|
|
|
private readonly TransferDestinationDal _transferDestinationDal;
|
|
private readonly AdminDal _adminDal;
|
|
private readonly ILogger<TransferDataAPIController> _logger;
|
|
|
|
public TransferDataAPIController(ILogger<TransferDataAPIController> logger, TransferDestinationDal transferDestinationDal, AdminDal adminDal)
|
|
{
|
|
_logger = logger;
|
|
_transferDestinationDal = transferDestinationDal;
|
|
_adminDal = adminDal;
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpGet]
|
|
[Route("GetTransferDestinations")]
|
|
public async Task<IEnumerable<TransferDestination>> GetTransferDestinations()
|
|
{
|
|
return await _transferDestinationDal.Context.TransferDestinations.ToListAsync();
|
|
}
|
|
|
|
[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("CreateTransferDestination")]
|
|
public async Task<IActionResult> CreateTransferDestination([FromBody] JsonElement SerializedTransferDestinationModel)
|
|
{
|
|
Console.WriteLine("CreateTransferDestination called!");
|
|
if (string.IsNullOrEmpty(SerializedTransferDestinationModel.GetRawText()))
|
|
{
|
|
return BadRequest("SerializedTramsferDestinationWizardModel is required");
|
|
}
|
|
else
|
|
{
|
|
TransferDestinationWizardModel? transferDestinationModel = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestinationWizardModel>();
|
|
|
|
if (transferDestinationModel != null)
|
|
{
|
|
|
|
var id = Guid.NewGuid();
|
|
TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString);
|
|
|
|
|
|
if (string.IsNullOrEmpty(transferDestinationModel.Name) || string.IsNullOrEmpty(transferDestinationModel.AddressString))
|
|
{
|
|
return BadRequest("Invalid request");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"TransferDestination to be created: {id}");
|
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.Name}");
|
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.Price}");
|
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.PriceType}");
|
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.AddressString}");
|
|
Console.WriteLine($"TransferDestination to be created: {transferDestination.Description}");
|
|
|
|
transferDestination.AddressId = Guid.Empty;
|
|
transferDestination.Price = 15000;
|
|
transferDestination.PriceType = PriceType.Fix;
|
|
|
|
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
|
|
await _transferDestinationDal.CreateTransferDestinationAsync(transferDestination);
|
|
return Ok(transferDestination);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
return BadRequest("Invalid request");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
} |