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(cargoId); if (cargo == null) { return NotFound(); } var route = objectSpace.GetObjectsQuery() .Where(wh => wh.Oid == cargo.Route.Oid) .Select(sl => new { //StartName = sl.StartPoint.Name, //Startpoint = sl.StartPoint.Point, //DestName = sl.DestinationPoint.Name, //Destpoint = sl.DestinationPoint.Point, 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(); //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 //}); //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 //}); return Ok(points); } catch (Exception ex) { return StatusCode(500, ex.Message); } } } }