This commit is contained in:
2021-02-27 20:42:47 +00:00
parent d92774ebdf
commit 8097175314
4 changed files with 66 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace AyaNova.Api.Controllers
@@ -148,7 +150,26 @@ namespace AyaNova.Api.Controllers
return NoContent();
}
/// <summary>
/// Get restock required list for vendor specified or any vendor if no vendor specified
/// </summary>
/// <param name="vendorId">optional vendor id will return matches to Part objects manufacturer, wholesaler or alternative wholesaler</param>
/// <returns>PurchaseOrder</returns>
[HttpGet("restock-by-vendor/{vendorId}")]
public async Task<IActionResult> GetPurchaseOrder([FromRoute] long? vendorId)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
PurchaseOrderBiz biz = PurchaseOrderBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
if (null == vendorId)
return Ok(ApiOkResponse.Response(await ct.ViewRestockRequired.OrderBy(z => z.RequiredQuantity).ToListAsync()));
else
return Ok(ApiOkResponse.Response(await ct.ViewRestockRequired.Where(z => z.ManufacturerId == vendorId || z.WholesalerId == vendorId || z.AlternativeWholesalerId == vendorId).OrderBy(z => z.RequiredQuantity).ToListAsync()));
}