public IEnumerable <AdminColleagueDiscountVM> GetAllForAdmin(SearchColleagueDiscountVM search) { var products = _shopContext.Products.Select(p => new { p.Id, p.Name }).ToList(); var query = _context.ColleagueDiscounts.Select(c => new AdminColleagueDiscountVM() { Id = c.Id, CreationDate = c.CreationTime.ToFarsi(), DiscountRate = c.DiscountRate, ProductId = c.ProductId, }); if (search.ProductId > 0) { query = query.Where(c => c.ProductId == search.ProductId); } var discounts = query.ToList(); discounts.ForEach(c => c.ProductName = products.Find(p => p.Id == c.ProductId)?.Name); return(discounts); }
public void OnGet(SearchColleagueDiscountVM search) { Products = new SelectList(_productApplication.GetProductModelForSearch(), "Id", "Name"); Discounts = _colleagueDiscountApplication.GetAllForAdmin(search); }