コード例 #1
0
        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);
        }
コード例 #2
0
 public IEnumerable <AdminInventoryVM> GetAllForAdmin(SearchInventoryVM search) => _inventoryRepository.GetAllForAdmin(search);
コード例 #3
0
 public void OnGet(SearchInventoryVM search)
 {
     Products    = new SelectList(_productApplication.GetProductModelForSearch(), "Id", "Name");
     Inventories = _inventoryApplication.GetAllForAdmin(search);
 }