in src/Modules/SimplCommerce.Module.Inventory/Areas/Inventory/Controllers/StockApiController.cs [37:82]
public async Task<IActionResult> List(long warehouseId, [FromBody] SmartTableParam param)
{
var currentUser = await _workContext.GetCurrentUser();
var warehouse = _warehouseRepository.Query().FirstOrDefault(x => x.Id == warehouseId);
if(warehouse == null)
{
return NotFound();
}
if (!User.IsInRole("admin") && warehouse.VendorId != currentUser.VendorId)
{
return BadRequest(new { error = "You don't have permission to manage this warehouse" });
}
var query = _stockRepository.Query().Where(x => x.WarehouseId == warehouseId && !x.Product.HasOptions && !x.Product.IsDeleted);
if (param.Search.PredicateObject != null)
{
dynamic search = param.Search.PredicateObject;
if (search.ProductName != null)
{
string productName = search.ProductName;
query = query.Where(x => x.Product.Name.Contains(productName));
}
if (search.ProductSku != null)
{
string productSku = search.productSku;
query = query.Where(x => x.Product.Sku.Contains(productSku));
}
}
var products = query.ToSmartTableResult(
param,
x => new
{
x.Id,
x.ProductId,
ProductName = x.Product.Name,
ProductSku = x.Product.Sku,
x.Quantity,
AdjustedQuantity = 0
});
return Ok(products);
}