This commit is contained in:
@@ -300,7 +300,7 @@ namespace AyaNova.Api.Controllers
|
||||
+ $"where aworkorderitemunit.unitid={id} "
|
||||
+ "order by aworkorder.serial DESC "
|
||||
+ "limit 3";
|
||||
using (var cmd = ct.Database.GetDbConnection().CreateCommand())
|
||||
using (var cmd = ct.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
await ct.Database.OpenConnectionAsync();
|
||||
cmd.CommandText = q;
|
||||
@@ -343,5 +343,37 @@ namespace AyaNova.Api.Controllers
|
||||
public string WarrantyTerms { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Unit Contract name/id if active and not expired
|
||||
/// </summary>
|
||||
/// <param name="id">UnitId</param>
|
||||
/// <returns>Contract name and Id</returns>
|
||||
[HttpGet("active-contract/{id}")]
|
||||
public async Task<IActionResult> GetUnitActiveContract([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 ret = new NameIdItem { Name = string.Empty, Id = 0 };
|
||||
var UnitContractInfo = await ct.Unit.AsNoTracking().Where(x => x.Id == id).Select(x => new { x.ContractId, x.ContractExpires }).FirstOrDefaultAsync();
|
||||
if (UnitContractInfo == null || UnitContractInfo.ContractExpires < DateTime.UtcNow)//none or expired
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
|
||||
var c = await ct.Contract.AsNoTracking().FirstOrDefaultAsync(x => x.Id == UnitContractInfo.ContractId);
|
||||
if (c == null || c.Active == false)
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
|
||||
ret.Name = c.Name;
|
||||
ret.Id = c.Id;
|
||||
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user