private FavoriteCollectionResponse Get(float version, int userId, PagerRequest pagerRequest, CoordinateInfo coordinate, FavoriteSortOrder sortOrder, SourceType sourceType)
        {
           
                  FavoriteCollectionResponse response;
                  int totalCount;
                  if (version >= 2.1)
                  {
                      var entitys = _favoriteRepository.Get(userId, pagerRequest, out totalCount, sortOrder, sourceType);

                      var list = MappingManager.FavoriteCollectionResponseMapping(entitys, coordinate);

                      response = new FavoriteCollectionResponse(pagerRequest, totalCount) { Favorites = list };
                  }
                  else
                  {
                      var entitys = _favoriteRepository.GetPagedList(userId, pagerRequest, out totalCount, sortOrder, sourceType);

                      response = MappingManager.FavoriteCollectionResponseMapping(entitys, coordinate);
                      response.Index = pagerRequest.PageIndex;
                      response.Size = pagerRequest.PageSize;
                      response.TotalCount = totalCount;
                  }

                  return response;
        }
Esempio n. 2
0
        public FavoriteCollectionResponse FavoriteCollectionResponseMapping(List<FavoriteEntity> source,
                                                                                   CoordinateInfo coordinateInfo)
        {
            if (source == null || source.Count == 0)
            {
                return new FavoriteCollectionResponse(new PagerRequest(1, 1)) { Favorites = new List<FavoriteInfoResponse>(0) };
            }

            //var storeids = source.Select(v => v.Store_Id).Distinct().Where(v => v != 0);
            //var dic = new Dictionary<int, List<int>>();
            var ms = source.Where(v => v.FavoriteSourceType == (int)SourceType.Promotion).Select(s => s.FavoriteSourceId).Distinct().ToList();
            var ps = source.Where(v => v.FavoriteSourceType == (int)SourceType.Product).Select(s => s.FavoriteSourceId).Distinct().ToList();

            //var stores = StoreResponseMapping(_storeRepository.GetListByIds(storeids.ToList()), coordinateInfo).ToList();
            var promotions = _promotionRepository.GetList(ms);
            var products = _productRepository.GetList(ps);

            var items = ItemsInfoResponseMapping(products, promotions).ToList();

            var t = new List<FavoriteInfoResponse>(items.Count);
            foreach (var i in items)
            {
                var a = Mapper.Map<ItemsInfoResponse, FavoriteInfoResponse>(i);
                a.FavoriteSourceId = i.Id;
                a.FavoriteSourceName = i.Name;
                a.FavoriteSourceType = i.SourceType;
                var r = source.FirstOrDefault(v => v.FavoriteSourceId == i.Id && v.FavoriteSourceType == i.SourceType);

                a.Id = r == null ? 0 : r.Id;
                a.StoreId = i.Store_Id;
                t.Add(a);
            }


            //TODO: 产品这个需要优化
            var result = new FavoriteCollectionResponse(new PagerRequest(1, source.Count), source.Count)
            {
                Favorites = t
            };

            return result;

            ////pp rs

            //var productResource = ResourceInfoResponsesMapping(GetListResourceEntities(SourceType.Product, ps)).ToList();
            //var msresource = ResourceInfoResponsesMapping(GetListResourceEntities(SourceType.Promotion, ms)).ToList();

            ////TODO: 产品这个需要优化
            //var result = new FavoriteCollectionResponse(new PagerRequest(1, source.Count), source.Count)
            //{
            //    Favorites = new List<FavoriteInfoResponse>(source.Count)
            //};
            //foreach (var s in source)
            //{
            //    //var n = String.Empty;
            //    FavoriteInfoResponse response = null;
            //    switch (s.FavoriteSourceType)
            //    {
            //        case (int)SourceType.Promotion:
            //            var p = promotions.FirstOrDefault(v => v.Id == s.FavoriteSourceId);
            //            response = FavoriteInfoResponseMapping(s, p);

            //            response.Resources = p == null ? new List<ResourceInfoResponse>(0) : msresource.Where(v => v.SourceId == p.Id && v.SourceType == (int)SourceType.Promotion).ToList();
            //            break;
            //        case (int)SourceType.Product:
            //            var t = products.FirstOrDefault(v => v.Id == s.FavoriteSourceId);
            //            response = FavoriteInfoResponseMapping(s, t);

            //            response.Resources = t == null ? new List<ResourceInfoResponse>(0) :
            //                productResource.Where(v => v.SourceId == t.Id && v.SourceType == (int)SourceType.Product).ToList();

            //            break;
            //    }

            //    if (response != null)
            //    {
            //        var store = stores.SingleOrDefault(v => v.Id == s.Store_Id);
            //        response.Store = store;
            //        response.StoreId = store == null ? 0 : store.Id;

            //        result.Favorites.Add(response);
            //    }
            //}

            //return result;
        }