public async Task <IEnumerable <GoodsDTO> > GetOnlineGoodsByGoodsCategoryName(string goodsCategoryName) { var goodsList = _onlineGoodsRepository.GetFiltered(o => o.GoodsCategoryName == goodsCategoryName).ToList(); var result = new List <GoodsDTO>(); foreach (var item in goodsList) { item.ResolveAddress(); result.Add(new GoodsDTO { Address = item.Address, ApplicationId = item.ApplicationId, Category = item.Category, Description = item.Description, Detail = item.Detail, Distance = "", DistributionScope = item.DistributionScope, GoodsCategoryName = item.GoodsCategoryName, Id = item.Id, MarketPrice = item.MarketPrice, UnitPrice = item.UnitPrice, OrganizationId = item.StoreId, Unit = item.Unit, SubCategory = item.SubCategory, Title = item.Title, VideoPath = item.VideoPath, StoreId = item.StoreId, Order = item.Order, ItemNumber = item.ItemNumber, OptionalPropertyJsonObject = item.OptionalPropertyJsonObject, OrganizationLogoUrl = "", Stock = item.Stock, Status = item.Status }); } return(result); }
public async Task <IEnumerable <GoodsDTO> > GetOnlineGoods(string key, string category, string subCategory, int pageIndex, int pageSize) { IEnumerable <GoodsDTO> goods = null; var result = _onlineGoodsRepository.GetFiltered(o => o.Status == GoodsStatus.Shelved || o.Status == GoodsStatus.SoldOut || o.Status == GoodsStatus.UnShelved); if (!string.IsNullOrEmpty(key)) { result = result.Where(o => o.Title.Contains(key)); } if (!string.IsNullOrEmpty(category)) { result = result.Where(o => o.Category == category); } if (!string.IsNullOrEmpty(subCategory)) { result = result.Where(o => o.SubCategory == subCategory); } goods = result.Skip((pageIndex - 1) * pageSize).Take(pageSize).Select( item => new GoodsDTO { Category = item.Category, Description = item.Description, Detail = item.Detail, Id = item.Id, ItemNumber = item.ItemNumber, MarketPrice = item.MarketPrice, OptionalPropertyJsonObject = item.OptionalPropertyJsonObject, Status = item.Status, Stock = item.Stock, StoreId = item.StoreId, SubCategory = item.SubCategory, Title = item.Title, Unit = item.Unit, UnitPrice = item.UnitPrice, DistributionScope = item.DistributionScope }).ToList(); if (goods != null && goods.Count() > 0) { foreach (var item in goods) { item.GoodsImages = _onlineGoodsImageRepository.GetFiltered(o => o.GoodsId == item.Id).Select(image => new GoodsImageDTO { ImageId = image.ImageId, GoodsId = image.GoodsId, Id = image.Id }).ToList(); var imageIds = item.GoodsImages.Select(o => o.ImageId).ToList(); var images = await _imageServiceProxy.GetImagesByIds(imageIds); foreach (var img in item.GoodsImages) { var pic = images.FirstOrDefault(o => o.Id == img.ImageId); img.HttpPath = pic?.HttpPath; img.Title = pic?.Title; img.Description = pic?.Description; } } } return(goods); }