Exemplo n.º 1
0
        public IEnumerable<DealModel> SearchDeals(DealSearchQuery query)
        {
            var unitOfWork = this.unitOfWorkFactory.CreateUnitOfWork();

            IEnumerable<DealModel> deals;

            if (query.CategoryId != null)
            {
                var category =
                         unitOfWork.CreateDealCategoryRepository()
                        .GetAll()
                        .FirstOrDefault(c => c.Key.ToString().Equals(query.CategoryId));

                if (category == null)
                {
                    return new List<DealModel>();
                }

                deals = category.Deals;
            }
            else if (query.MerchantId != null)
            {
                var merchant = unitOfWork.CreateMerchantRepository().FindByKey(query.MerchantId);

                deals = merchant.Deals;
            }
            else
            {
                deals = unitOfWork.CreateDealRepository().GetAll();
            }

            if (query.ExcludeExpired)
            {
                deals = deals.Where(d => d.EndTime.CompareTo(DateTime.UtcNow) > 0);
            }

            if (!string.IsNullOrEmpty(query.SearchTerm))
            {

                deals = deals
                    .Where(d =>
                            ContainsIgnoreCase(d.ShortTitle, query.SearchTerm) ||
                            ContainsIgnoreCase(d.ShortDescription, query.SearchTerm) ||
                            ContainsIgnoreCase(d.LongTitle, query.SearchTerm) ||
                            ContainsIgnoreCase(d.LongDescription, query.SearchTerm))
                    .ToList();
            }

            return deals.Where(d => d.Status == DealStatus.Published);
        }
Exemplo n.º 2
0
        public IEnumerable<FrontEndDeal> Get()
        {
            var query = Request.GetQueryNameValuePairs().ToList();
            var searchQuery = new DealSearchQuery();

            var searchTerm = query.FirstOrDefault(k => k.Key.Equals("search", StringComparison.OrdinalIgnoreCase));
            var categoryId = query.FirstOrDefault(k => k.Key.Equals("categoryid", StringComparison.OrdinalIgnoreCase));
            var merchantId = query.FirstOrDefault(k => k.Key.Equals("merchantId", StringComparison.OrdinalIgnoreCase));
            var excludeExpired = query.FirstOrDefault(k => k.Key.Equals("excludeExpired", StringComparison.OrdinalIgnoreCase));

            // Category id, search term, sorted by, all
            if (KeyHasValue(categoryId))
            {
                searchQuery.CategoryId = categoryId.Value;
            }

            if (KeyHasValue(searchTerm))
            {
                searchQuery.SearchTerm = searchTerm.Value;
            }

            if (KeyHasValue(merchantId))
            {
                searchQuery.MerchantId = merchantId.Value;
            }

            if (KeyHasValue(excludeExpired))
            {
                searchQuery.ExcludeExpired = excludeExpired.Value.Equals("1");
            }

            //TODO: Combine search term and category.

            var convertedSearchResults = dealService.SearchDeals(searchQuery)
                .Select(d => {
                    var mapped = AutoMapper.Mapper.Map<FrontEndDeal>(d);

                    return mapped;
                })
                .ToList();

            foreach (var result in convertedSearchResults)
            {
                for (int i = 0; i < result.ThumbnailUrls.Count; i++)
                {
                    result.ThumbnailUrls[i] =
                        PathHelper.ConvertRelativeToAbsoluteDealImagePath(result.ThumbnailUrls[i]);
                }
            }

            return convertedSearchResults;
        }