public FrontEndSpecificDeal GetSingle()
        {
            var query = Request.GetQueryNameValuePairs().ToList();
            var searchQuery = new SingleDealSearchQuery();

            var dealId = query.FirstOrDefault(k => k.Key.Equals("id", StringComparison.OrdinalIgnoreCase));
            var url = query.FirstOrDefault(k => k.Key.Equals("url", StringComparison.OrdinalIgnoreCase));

            if (KeyHasValue(dealId))
            {
                searchQuery.Id = dealId.Value;
            }

            if (KeyHasValue(url))
            {
                searchQuery.CanonicalUrl = url.Value;
            }

            var searchResult = dealService.SearchSingleDeal(searchQuery);

            var convertedSearchResult = AutoMapper.Mapper.Map<DealModel, FrontEndSpecificDeal>(searchResult);

            for (int i = 0; i < convertedSearchResult.ImageUrls.Count; i++)
            {
                convertedSearchResult.ImageUrls[i] =
                    PathHelper.ConvertRelativeToAbsoluteDealImagePath(convertedSearchResult.ImageUrls[i]);
            }

            var orderCount = this.orderService.GetOrderCount(convertedSearchResult.Id);
            convertedSearchResult.OrderCount = orderCount;

            return convertedSearchResult;
        }
Beispiel #2
0
        /// <summary>
        /// We could actually make single and multiple deals grouped under the same method but
        /// due to performance considerations it's wiser to split them into two.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public DealModel SearchSingleDeal(SingleDealSearchQuery query)
        {
            var unitOfWork = this.unitOfWorkFactory.CreateUnitOfWork();
            var repository = unitOfWork.CreateDealRepository();

            if (!string.IsNullOrEmpty(query.Id))
            {
                return repository.GetAll().FirstOrDefault(d => d.Key.ToString().Equals(query.Id));
            }

            if (!string.IsNullOrEmpty(query.CanonicalUrl))
            {
                return repository.GetAll().FirstOrDefault(d => d.CanonicalUrl.Equals(query.CanonicalUrl));
            }

            return null;
        }