コード例 #1
0
        public Task <List <VendorProductViewModel> > GetVendorProductByShopId(SearchShopProductViewModel searchProduct)
        {
            var    shop       = _context.Shops.Where(x => x.IsActive == true && x.Id == searchProduct.ShopId).FirstOrDefault();
            int    totalSkip  = searchProduct.PageSize * (searchProduct.PageNumber - 1);
            string whereClose = $" where IsActive = true and shopId='{shop.Id}'";

            if (searchProduct.BrandId != "null")
            {
                whereClose = whereClose + @$ " and BrandId ='{searchProduct.BrandId}' ";
            }
            if (searchProduct.CategoryId != "null")
            {
                whereClose = whereClose + @$ " and CategoryId ='{searchProduct.CategoryId}' ";
                if (searchProduct.SubCategoryId != "null")
                {
                    whereClose = whereClose + @$ " and SubCategoryId ='{searchProduct.SubCategoryId}' ";
                }
            }
            if (shop != null)
            {
                if (!string.IsNullOrEmpty(searchProduct.ProductId))
                {
                    whereClose = whereClose + @$ " and v.ProductId ='{searchProduct.ProductId}' ";
                }

                if (shop.IsPriceVisible)
                {
                    var result = _context.VendorProducts.FromSqlRaw($"select v.Id,v.IsOutStock,v.ProductId,v.ProductName,v.ProductUrl,v.Selling,v.MRP,v.ItemCount,v.Discount,u.UnitType,v.Description,N'{shop.CurrencyType}' as CurrencyType from VendorProduct.Vendor{shop.tableName}Products v join Unit u on v.UnitId = u.Id {whereClose} order by v.Id OFFSET {totalSkip} ROWS FETCH NEXT {searchProduct.PageSize} ROWS ONLY;")
                                 .Select(x => new VendorProductViewModel
                    {
                        Id           = x.Id,
                        ProductId    = x.ProductId,
                        ProductName  = x.ProductName,
                        Description  = x.Description,
                        Discount     = x.Discount,
                        IsOutStock   = x.IsOutStock,
                        MRP          = x.MRP,
                        ItemCount    = x.ItemCount.Value,
                        ProductUrl   = _documentStorage.GetProductUri(x.ProductUrl).Result,
                        Selling      = x.Selling,
                        UnitType     = x.UnitType,
                        CurrencyType = x.CurrencyType
                    }).AsQueryable();

                    return(Task.FromResult(result.ToList()));
                }
                else
                {
                    var result = _context.VendorProducts.FromSqlRaw($"select v.Id,v.IsOutStock,v.ProductId,v.ProductName,v.ProductUrl,v.ItemCount,u.UnitType,v.Description,N'{shop.CurrencyType}' as CurrencyType from VendorProduct.Vendor{shop.tableName}Products v join Unit u on v.UnitId = u.Id {whereClose} order by v.Id OFFSET {totalSkip} ROWS FETCH NEXT {searchProduct.PageSize} ROWS ONLY;")
                                 .Select(x => new VendorProductViewModel
                    {
                        Id           = x.Id,
                        ProductId    = x.ProductId,
                        ProductName  = x.ProductName,
                        Description  = x.Description,
                        Discount     = 0,
                        IsOutStock   = x.IsOutStock,
                        MRP          = 0,
                        ItemCount    = x.ItemCount.Value,
                        ProductUrl   = _documentStorage.GetProductUri(x.ProductUrl).Result,
                        Selling      = 0,
                        UnitType     = x.UnitType,
                        CurrencyType = x.CurrencyType
                    }).AsQueryable();

                    return(Task.FromResult(result.ToList()));
                }
            }

            throw new NotImplementedException();
        }
コード例 #2
0
        public async Task <ActionResult <IEnumerable <VendorProductViewModel> > > GetProductByShopId(SearchShopProductViewModel searchProduct)
        {
            var result = await _singleton.vendorRepository.GetVendorProductByShopId(searchProduct);

            return(result);
        }