Beispiel #1
0
        public async Task <decimal> GetProductsTotalByIdList(string productIds)
        {
            decimal num;
            decimal num1;
            decimal num2 = new decimal();

            if (productIds.Trim().Length > 0)
            {
                string      str      = productIds;
                char[]      chrArray = new char[] { ',' };
                List <long> list     = str.Split(chrArray).Select <string, long>(new Func <string, long>(long.Parse)).ToList <long>();
                IRepository <Product, long> repository = this._productRepository;
                List <Product> allListAsync            = await repository.GetAllListAsync((Product x) => list.Contains(x.Id) && x.TenantId == this.AbpSession.TenantId.Value);

                List <Product> products = allListAsync;
                if (products.Any <Product>())
                {
                    foreach (Product product in products)
                    {
                        IRepository <ProductPrice, long> repository1 = this._productPriceRepository;
                        ProductPrice productPrice = await repository1.FirstOrDefaultAsync((ProductPrice x) => x.ProductId == product.Id && x.IsActive);

                        ProductPrice productPrice1 = productPrice;
                        if (!(productPrice1 != null) || !decimal.TryParse(productPrice1.UnitPrice.ToString(), out num1))
                        {
                            continue;
                        }
                        num2 = num2 + num1;
                    }
                }
                else
                {
                    num = num2;
                    return(num);
                }
            }
            num = num2;
            return(num);
        }
Beispiel #2
0
        public async Task <ListResultDto <ProductListDto> > GetProductsByTenantId(int tenantId, bool active = true, string query = "")
        {
            IQueryable <Product> all      = this._productRepository.GetAll();
            IQueryable <Product> products =
                from p in all
                where p.TenantId == tenantId
                select p;
            IQueryable <Product> products1 = products.WhereIf <Product>(!string.IsNullOrEmpty(query), (Product p) => p.Description.Contains(query) || p.Name.Contains(query) || p.Reference.Contains(query) || p.Sku.Contains(query));
            bool           flag            = active;
            List <Product> listAsync       = await products1.WhereIf <Product>(flag, (Product p) => p.IsActive == active).OrderBy <Product>("Name", new object[0]).ToListAsync <Product>();

            List <ProductListDto> productListDtos = listAsync.MapTo <List <ProductListDto> >();
            List <long>           nums            = new List <long>();

            foreach (ProductListDto productOptionDtos in productListDtos)
            {
                IRepository <ProductOption, long> repository = this._productOptionRepository;
                List <ProductOption> allListAsync            = await repository.GetAllListAsync((ProductOption x) => x.ProductId == (long)productOptionDtos.Id && x.IsActive);

                List <ProductOption> productOptions = allListAsync;
                if (!productOptions.Any <ProductOption>())
                {
                    productOptionDtos.ProductOptions = new List <ProductOptionDto>();
                }
                else
                {
                    foreach (ProductOption productOption in productOptions)
                    {
                        if (productOptionDtos.ProductOptions == null)
                        {
                            productOptionDtos.ProductOptions = new List <ProductOptionDto>();
                        }
                        productOptionDtos.ProductOptions.Add(productOption.MapTo <ProductOptionDto>());
                    }
                }
                IRepository <ProductPrice, long> repository1 = this._productPriceRepository;
                List <ProductPrice> productPrices            = await repository1.GetAllListAsync((ProductPrice x) => x.ProductId == (long)productOptionDtos.Id && x.IsActive);

                List <ProductPrice> productPrices1 = productPrices;
                if (productPrices1.Any <ProductPrice>())
                {
                    List <ProductPrice> .Enumerator enumerator = productPrices1.GetEnumerator();
                    try
                    {
                        if (enumerator.MoveNext())
                        {
                            ProductPrice current = enumerator.Current;
                            if (productOptionDtos.ProductPrices == null)
                            {
                                productOptionDtos.ProductPrices = new List <PriceDto>();
                            }
                            productOptionDtos.ProductPrices.Add(current.MapTo <PriceDto>());
                        }
                    }
                    finally
                    {
                        ((IDisposable)enumerator).Dispose();
                    }
                }
            }
            return(new ListResultDto <ProductListDto>(productListDtos));
        }