This commit is contained in:
@@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
@@ -176,7 +176,50 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Unit list by tag and optionally customer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="searchParam"></param>
|
||||||
|
/// <returns>List of units</returns>
|
||||||
|
[HttpPost("bulk-add-selection-list")]
|
||||||
|
public async Task<IActionResult> GetPartSerials([FromBody] UnitListByTagParams searchParam)
|
||||||
|
{
|
||||||
|
if (!serverState.IsOpen)
|
||||||
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
|
||||||
|
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Part))
|
||||||
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
if (searchParam.restrictToCustomerId == null || searchParam.restrictToCustomerId == 0)
|
||||||
|
{
|
||||||
|
//any customer
|
||||||
|
//https://www.npgsql.org/efcore/mapping/array.html#operation-translation
|
||||||
|
//array1.All(i => array2.Contains(i))
|
||||||
|
|
||||||
|
// var right = contextMock.Where(x => (new List<string> { "harry potter", "the lord of the rings" }).Any(y => x.Title.ToLower().Contains(y.ToLower()))).ToList();
|
||||||
|
|
||||||
|
var ret = await ct.Unit.AsNoTracking().Where(z => searchParam.tags.All(y => (z.Tags.Contains(y)))).Select(z => new { z.Id, z.Serial }).ToListAsync();
|
||||||
|
return Ok(ApiOkResponse.Response(ret));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//include customer
|
||||||
|
List<NameIdItem> retList = new List<NameIdItem>();
|
||||||
|
var unitz = await ct.Unit.AsNoTracking().Where(z => z.Active == true).Where(z => searchParam.tags.All(y => (z.Tags.Contains(y)))).Select(z => new { z.CustomerId, z.Serial }).ToListAsync();
|
||||||
|
foreach (var u in unitz)
|
||||||
|
{
|
||||||
|
var cviz = await ct.Customer.AsNoTracking().Where(z => z.Id == u.CustomerId).Select(z => z.Name).FirstOrDefaultAsync();
|
||||||
|
retList.Add(new NameIdItem { Name = $"{cviz} - {u.Serial}")
|
||||||
|
|
||||||
|
}
|
||||||
|
return Ok(ApiOkResponse.Response(o));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public record UnitListByTagParams(List<string> tags, long? restrictToCustomerId);
|
||||||
//------------
|
//------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user