Exemplo n.º 1
0
        public void OnGet(ColleagueSearchModel searchModel)
        {
            var products = _productApplication.GetProducts();

            Products           = new SelectList(products, "Id", "Name");
            ColleagueDiscounts = _colleagueDiscountApplication.Search(searchModel);
        }
        public List <ColleagueDiscountViewModel> Search(ColleagueSearchModel searchModel)
        {
            var products = _shopContext.Products.Select(x => new { x.Id, x.Name }).ToList();

            var query = _context.ColleagueDiscounts.Select(x => new ColleagueDiscountViewModel
            {
                Id           = x.Id,
                CreationDate = x.CreationDate.ToFarsi(),
                DiscountRate = x.DiscountRate,
                ProductId    = x.ProductId,
                IsRemoved    = x.IsRemoved
            });

            if (searchModel.ProductId > 0)
            {
                query = query.Where(x => x.ProductId == searchModel.ProductId);
            }

            var discounts = query.OrderByDescending(x => x.Id).ToList();

            discounts.ForEach(discount => discount.Product = products.FirstOrDefault(x => x.Id == discount.ProductId)?.Name);

            return(discounts);
        }
Exemplo n.º 3
0
 public List <ColleagueDiscountViewModel> Search(ColleagueSearchModel searchModel)
 {
     return(_colleagueDiscountRepository.Search(searchModel));
 }