Ejemplo n.º 1
0
        public async Task <List <ProductSaleOutPut> > GetSuccessSaleProduct(ProductSaleOutPut productSaleOutPut)
        {
            var userId = ((UserIdentity)User.Identity).UserId;

            var res = await Task.Run(() => db.Product_Sales.AsNoTracking()
                                     .Where(p => p.Is_Or == 30 && p.del_ort == false));


            var result = await Task.Run(() => db.Product_Sales
                                        .Where(p => p.Is_Or == 30 && p.del_ort == false)
                                        .Select(p => new ProductSaleOutPut
            {
                Id                  = p.Id.ToString(),
                FishProductId       = p.FishProductId.ToString(),
                z_FnishedProduct    = p.z_FnishedProduct,
                ProductNumber       = p.ProductNumber,
                Userid              = p.userDetails.Id.ToString(),
                userDetails         = p.userDetails,
                Des                 = p.Des,
                Count               = res.Count(),
                QuasiPurchaseNumber = p.QuasiPurchaseNumber,
                Is_Or               = p.Is_Or,
                Behoof              = p.Behoof,
                Sale_Price          = p.Sale_Price,
                SupplierId          = p.SupplierId.ToString(),
                Supplier            = p.Supplier,
                Sale_Time           = p.Sale_Time
            })
                                        );

            if (productSaleOutPut.U_Id == 1)
            {
                result = await Task.Run(() => result.Where(p => p.userDetails.Id == userId).OrderBy(p => p.Sale_Time)
                                        .Skip((productSaleOutPut.PageIndex *productSaleOutPut.PageSize) - productSaleOutPut.PageSize).Take(productSaleOutPut.PageSize));

                return(await result.ToListAsync());
            }

            if (productSaleOutPut.PageIndex != null && productSaleOutPut.PageSize != null && !string.IsNullOrWhiteSpace(productSaleOutPut.RelName) || !string.IsNullOrWhiteSpace(productSaleOutPut.Name))
            {
                result = await Task.Run(() => result.Where(p => p.z_FnishedProduct.Name == productSaleOutPut.Name || p.userDetails.RealName == productSaleOutPut.RelName).OrderBy(p => p.Sale_Time)
                                        .Skip((productSaleOutPut.PageIndex *productSaleOutPut.PageSize) - productSaleOutPut.PageSize).Take(productSaleOutPut.PageSize));

                return(await result.ToListAsync());
            }

            result = await Task.Run(() => result.OrderBy(p => p.Sale_Time)
                                    .Skip((productSaleOutPut.PageIndex *productSaleOutPut.PageSize) - productSaleOutPut.PageSize).Take(productSaleOutPut.PageSize));


            return(await result.ToListAsync());
        }
Ejemplo n.º 2
0
        public async Task <List <ProductSaleOutPut> > GetSaleProduct(ProductSaleOutPut productSaleOutPut)
        {
            var userId = ((UserIdentity)User.Identity).UserId;

            var resul = Task.Run(() => db.UserDetails.AsNoTracking().FirstOrDefault(p => p.Id == userId && p.IsDelete == false));
            var dep   = resul.Result.User.DepartmentId;

            //var res = await Task.Run(() => db.Product_Sales.AsNoTracking()
            //.Where(p => p.userDetails.User.DepartmentId == dep && p.del_ort == false && p.Is_Or == 1 || p.Is_Or == 6));


            var result = await Task.Run(() => db.Product_Sales
                                        .Where(p => p.userDetails.User.DepartmentId == dep && p.del_ort == false && p.Is_Or == 1)
                                        .Select(p => new ProductSaleOutPut
            {
                Id               = p.Id.ToString(),
                FishProductId    = p.FishProductId.ToString(),
                z_FnishedProduct = p.z_FnishedProduct,
                ProductNumber    = p.ProductNumber,
                Userid           = p.userDetails.Id.ToString(),
                userDetails      = p.userDetails,
                Des              = p.Des,
                // Count = res.Count(),
                QuasiPurchaseNumber = p.QuasiPurchaseNumber,
                Is_Or      = p.Is_Or,
                Behoof     = p.Behoof,
                Sale_Price = p.Sale_Price,
                SupplierId = p.SupplierId.ToString(),
                Supplier   = p.Supplier,
                Sale_Time  = p.Sale_Time
            })
                                        );

            if (productSaleOutPut.PageIndex != null && productSaleOutPut.PageSize != null && !string.IsNullOrWhiteSpace(productSaleOutPut.RelName) || !string.IsNullOrWhiteSpace(productSaleOutPut.Name))
            {
                result = await Task.Run(() => result.Where(p => p.z_FnishedProduct.Name == productSaleOutPut.Name || p.userDetails.RealName == productSaleOutPut.RelName).OrderBy(p => p.Sale_Time)
                                        .Skip((productSaleOutPut.PageIndex *productSaleOutPut.PageSize) - productSaleOutPut.PageSize).Take(productSaleOutPut.PageSize));

                var re = await result.ToListAsync();

                foreach (var item in re)
                {
                    item.Count = result.Count();
                }

                return(re);
            }

            if (productSaleOutPut.PageIndex != null && productSaleOutPut.PageSize != null)
            {
                result = await Task.Run(() => result.OrderBy(p => p.Sale_Time)
                                        .Skip((productSaleOutPut.PageIndex *productSaleOutPut.PageSize) - productSaleOutPut.PageSize).Take(productSaleOutPut.PageSize));

                var re = await result.ToListAsync();

                foreach (var item in re)
                {
                    item.Count = result.Count();
                }

                return(re);
            }



            return(await result.ToListAsync());



            //   return await result.ToListAsync().Result.Count();
        }