public List <CustomerDiscountViewModel> Search(CustomerDiscountSearchModel searchModel)
        {
            var products = _shopContext.Products.Select(x => new { x.Id, x.Name }).ToList();
            var query    = _context.CustomerDiscounts.Select(x => new CustomerDiscountViewModel
            {
                Id           = x.Id,
                ProductId    = x.ProductId,
                DiscountRate = x.DiscountRate,
                StartDate    = x.StartDate.ToFarsi(),
                StartDateGr  = x.StartDate,
                EndDate      = x.EndDate.ToFarsi(),
                EndDateGr    = x.EndDate,
                Reason       = x.Reason,
                CreationDate = x.CreationDate.ToFarsi()
            });

            if (searchModel.ProductId > 0)
            {
                query = query.Where(x => x.ProductId == searchModel.ProductId);
            }
            if (!string.IsNullOrWhiteSpace(searchModel.StartDate))
            {
                query = query.Where(x => x.StartDateGr > searchModel.StartDate.ToGeorgianDateTime());
            }
            if (!string.IsNullOrWhiteSpace(searchModel.EndDate))
            {
                query = query.Where(x => x.EndDateGr < searchModel.EndDate.ToGeorgianDateTime());
            }
            var discounts = query.OrderByDescending(x => x.Id).ToList();

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

            return(discounts);
        }
        public void OnGet(CustomerDiscountSearchModel searchModel)
        {
            var products = _productApplication.GetProducts();

            Products          = new SelectList(products, "Id", "Name");
            CustomerDiscounts = _customerDiscountApplication.Search(searchModel);
        }
Пример #3
0
        public List <CustomerDiscountViewModel> Search(CustomerDiscountSearchModel searchModel)
        {
            var products = _shopContext.Products.Select(p => new SelectProductViewModel {
                Id = p.Id, Name = p.Name
            })
                           .AsNoTracking().ToList();

            var query = _db.CustomerDiscounts.Select(cd => new CustomerDiscountViewModel()
            {
                Id           = cd.Id,
                ProductId    = cd.ProductId,
                GrStartDate  = cd.StartDate,
                GrEndDate    = cd.EndDate,
                FaStartDate  = cd.StartDate.ToFarsi(),
                FaEndDate    = cd.EndDate.ToFarsi(),
                Reason       = cd.Reason,
                DiscountRate = cd.DiscountRate,
                IsRemoved    = cd.IsRemoved,
                CreationDate = cd.CreationDate.ToFarsi()
            });

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

            if (!string.IsNullOrWhiteSpace(searchModel.StartDate))
            {
                query = query.Where(cd => cd.GrStartDate >= searchModel.StartDate.ToGeorgianDateTime());
            }

            if (!string.IsNullOrWhiteSpace(searchModel.StartDate))
            {
                query = query.Where(cd => cd.GrEndDate <= searchModel.EndDate.ToGeorgianDateTime());
            }

            var result = query.AsNoTracking().ToList();

            result.ForEach(cd => cd.Product = products.FirstOrDefault(p => p.Id == cd.ProductId)?.Name);
            return(result);
        }
Пример #4
0
        public List <CustomerDiscountViewModel> Search(CustomerDiscountSearchModel searchModel)
        {
            var query = _context.CustomerDiscounts.Select(c => new CustomerDiscountViewModel()
            {
                Id           = c.Id,
                EndDate      = c.EndDate.ToFarsi(),
                StartDate    = c.StartDate.ToFarsi(),
                ProductId    = c.ProductId,
                DiscountRate = c.DiscountRate,
                Reason       = c.Reason,
                EnddateGr    = c.EndDate,
                StartdateGr  = c.StartDate,
                CreationDate = c.CreationDate.ToFarsiFull()
            });

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

            if (!string.IsNullOrWhiteSpace(searchModel.StartDate) && !string.IsNullOrWhiteSpace(searchModel.EndDate))
            {
                query = query.Where(c => c.StartdateGr <= searchModel.EndDate.ToGeorgianDateTime() &&
                                    c.EnddateGr >= searchModel.StartDate.ToGeorgianDateTime());
            }

            var Products = _shopContext.Products.Select(c => new { c.Id, c.Name }).ToList();


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

            discounts.ForEach(discount =>
                              discount.ProductName = Products.FirstOrDefault(x => x.Id == discount.ProductId)?.Name);

            return(discounts);
        }
 public List <CustomerDiscountViewModel> Search(CustomerDiscountSearchModel searchModel)
 {
     return(_customerDiscountRepository.Search(searchModel));
 }