2024-09-02 10:07:25 +00:00
|
|
|
|
using DevExpress.ExpressApp.Core;
|
|
|
|
|
|
using DurnyklyYol.Blazor.Server.DTO;
|
|
|
|
|
|
using DurnyklyYol.Module.BusinessObjects;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DurnyklyYol.Blazor.Server.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
public class CargoController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly INonSecuredObjectSpaceFactory _nonSecuredObjectSpaceFactory;
|
|
|
|
|
|
public CargoController(INonSecuredObjectSpaceFactory nonSecuredObjectSpaceFactory) => _nonSecuredObjectSpaceFactory = nonSecuredObjectSpaceFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("Route/{cargoId}")]
|
|
|
|
|
|
public IActionResult GetRoute(Guid cargoId)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using var objectSpace = _nonSecuredObjectSpaceFactory.CreateNonSecuredObjectSpace(typeof(Cargo));
|
|
|
|
|
|
var cargo = objectSpace.GetObjectByKey<Cargo>(cargoId);
|
|
|
|
|
|
|
|
|
|
|
|
if (cargo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var route = objectSpace.GetObjectsQuery<Module.BusinessObjects.Route>()
|
|
|
|
|
|
.Where(wh => wh.Oid == cargo.Route.Oid)
|
|
|
|
|
|
.Select(sl => new
|
|
|
|
|
|
{
|
2024-09-26 06:06:05 +00:00
|
|
|
|
//StartName = sl.StartPoint.Name,
|
|
|
|
|
|
//Startpoint = sl.StartPoint.Point,
|
|
|
|
|
|
//DestName = sl.DestinationPoint.Name,
|
|
|
|
|
|
//Destpoint = sl.DestinationPoint.Point,
|
2024-09-02 10:07:25 +00:00
|
|
|
|
Points = sl.Points.OrderBy(ob => ob.Order).Select(p => p.Point)
|
|
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
if (route == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var points = route.Points.Select(p => new PointDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = p.Name,
|
|
|
|
|
|
Lat = p.Latitude,
|
|
|
|
|
|
Long = p.Longitude,
|
|
|
|
|
|
IsCurrent = cargo.CurrentPoint.Oid == p.Oid,
|
|
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
2024-09-26 06:06:05 +00:00
|
|
|
|
//points.Insert(0, new PointDto
|
|
|
|
|
|
//{
|
|
|
|
|
|
// //Name = route.StartName,
|
|
|
|
|
|
// //Lat = route.Startpoint?.Latitude ?? 0,
|
|
|
|
|
|
// //Long = route.Startpoint?.Longitude ?? 0,
|
|
|
|
|
|
// //IsCurrent = cargo.CurrentPoint.Oid == route.Startpoint?.Oid,
|
|
|
|
|
|
// DateAt = cargo.StartedAt
|
|
|
|
|
|
//});
|
2024-09-02 10:07:25 +00:00
|
|
|
|
|
2024-09-26 06:06:05 +00:00
|
|
|
|
//points.Add(new PointDto
|
|
|
|
|
|
//{
|
|
|
|
|
|
// //Name = route.DestName,
|
|
|
|
|
|
// //Lat = route.Destpoint?.Latitude ?? 0,
|
|
|
|
|
|
// //Long = route.Destpoint?.Longitude ?? 0,
|
|
|
|
|
|
// //IsCurrent = cargo.CurrentPoint.Oid == route.Destpoint?.Oid,
|
|
|
|
|
|
// DateAt = cargo.ArrivedAt
|
|
|
|
|
|
//});
|
2024-09-02 10:07:25 +00:00
|
|
|
|
|
|
|
|
|
|
return Ok(points);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
|
return StatusCode(500, ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|