public IEnumerable <AdminInventoryVM> GetAllForAdmin(SearchInventoryVM search) { var products = _shopContext.Products.Select(p => new { p.Id, p.Name }).ToList(); var query = _context.Inventories.Select(v => new AdminInventoryVM() { Id = v.Id, ProductId = v.ProductId, CreationDate = v.CreationTime.ToFarsi(), Price = v.Price, IsInStock = v.IsInStock, CurrentCount = v.CalculateStock() }); if (search.ProductId > 0) { query = query.Where(v => v.ProductId == search.ProductId); } if (search.IsInStock) { query = query.Where(v => !v.IsInStock); } var inventories = query.ToList(); inventories.ForEach(v => v.ProductName = products.FirstOrDefault(p => p.Id == v.ProductId)?.Name); return(inventories); }
public IEnumerable <AdminInventoryVM> GetAllForAdmin(SearchInventoryVM search) => _inventoryRepository.GetAllForAdmin(search);
public void OnGet(SearchInventoryVM search) { Products = new SelectList(_productApplication.GetProductModelForSearch(), "Id", "Name"); Inventories = _inventoryApplication.GetAllForAdmin(search); }