/// <summary> /// 获取所有产品列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <ProductDetail> GetProductDetail(GetProductByFilter input) { var customer = await _customerRepository.FirstOrDefaultAsync(input.CustomerId); if (customer == null) { throw new UserFriendlyException("客户信息不存在"); } var product = await _customerPriceRepository.FirstOrDefaultAsync(c => c.ProductId == input.CateId.Value && c.CustomerId == input.CustomerId); if (product == null) { throw new UserFriendlyException("该产品不存在"); } var dto = product.Product.MapTo <ProductDetail>(); dto.Price = product.Price; if (!product.Product.Profile.HasValue) { return(dto); } var file = await _binaryObjectManager.GetOrNullAsync(product.Product.Profile.Value); if (file != null) { dto.ProfileUrl = Host + file.Url; } dto.CanBuy = customer.Balance > product.Price; return(dto); }
/// <summary> /// 获取所有产品列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <List <ProductDetail> > GetProducts(GetProductByFilter input) { var products = await _customerPriceRepository.GetAll().Where(c => c.Product.IsActive && c.Price > 0 && c.CustomerId == input.CustomerId) .WhereIf(input.CateId.HasValue, c => c.Product.LevelTwoId == input.CateId.Value).ToListAsync(); var output = new List <ProductDetail>(); if (!products.Any()) { return(output); } foreach (var oc in products) { var dto = oc.Product.MapTo <ProductDetail>(); dto.Price = oc.Price; if (oc.Product.Profile.HasValue) { var file = await _binaryObjectManager.GetOrNullAsync(oc.Product.Profile.Value); if (file != null) { dto.ProfileUrl = Host + file.Url; } } output.Add(dto); } return(output); }