This commit is contained in:
@@ -11,6 +11,7 @@ using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -195,7 +196,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
if (searchParam.tags.Count == 0) //note: this error only applies to api users so not translated
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "tags", "tags are required"));
|
||||
|
||||
|
||||
//build query
|
||||
//select id,serial,customerid from aunit where aunit.tags @> array['red','blue'::varchar(255)] AND customerid=19
|
||||
/*
|
||||
@@ -238,5 +239,69 @@ namespace AyaNova.Api.Controllers
|
||||
//------------
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Unit service and warranty info
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Service and warranty info</returns>
|
||||
[HttpGet("service-warranty-info/{id}")]
|
||||
public async Task<IActionResult> GetUnitServiceWarrantyInfo([FromRoute] long id)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Unit))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
var u = await ct.Unit.AsNoTracking().Where(x => x.Id == id).FirstOrDefaultAsync();
|
||||
if (u == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
UnitModel unitModel = null;
|
||||
if (u.UnitModelId != null)
|
||||
unitModel = await ct.UnitModel.AsNoTracking().Where(x => x.Id == u.UnitModelId).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
if (u.OverrideModelWarranty || unitModel == null)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//last workorders
|
||||
List<RecentWorkOrder> recentWorkOrders=new List<RecentWorkOrder>();
|
||||
var lastWoItemIds = await ct.WorkOrderItemUnit.AsNoTracking().Where(z => z.UnitId == id).OrderByDescending(z => z.Id).Take(3).Select(z => z.WorkOrderItemId).ToListAsync();
|
||||
|
||||
foreach (long woitemid in lastWoItemIds){
|
||||
var woid=await ct.WorkOrderItem.AsNoTracking().Where(x => x.Id == woitemid).OrderByDescending(x=>x.WorkOrderId).Select(x => x.WorkOrderId).FirstOrDefaultAsync();
|
||||
recentWorkOrders.Add(
|
||||
await ct.WorkOrder.AsNoTracking().Where(x=>x.Id==woid).Select(x=>new RecentWorkOrder(x.Serial,x.Id,x.ServiceDate)).FirstOrDefaultAsync();
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return Ok(ApiOkResponse.Response(new
|
||||
{
|
||||
unit = new AddressRecord(u.Serial, u.Address, u.City, u.Region, u.Country, u.Latitude, u.Longitude)
|
||||
}));
|
||||
}
|
||||
|
||||
private record RecentWorkOrder(long? Serial, long? Id, DateTime? ServiceDate);
|
||||
|
||||
private record UnitServiceWarrantyInfo(
|
||||
List<RecentWorkOrder> RecentWorkOrders,
|
||||
DateTime? PurchaseDate,
|
||||
string PurchasedFromVendor,
|
||||
long? PurchaseFromVendorId,
|
||||
string PurchaseReceiptNumber,
|
||||
bool LifeTimeWarranty,
|
||||
DateTime? WarrantyExpiryDate,
|
||||
string WarrantyTerms
|
||||
);
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user