Exemplo n.º 1
0
        public ActionResult Details(int productID) 
        {
            var query = new ProductQuery() { 
                                ProductID = productID
                                };

            var model = _mediator.Enquire<ProductQuery, ProductModel>(query);

            return View(model);
        }
Exemplo n.º 2
0
        public dynamic GetById(string id)
        {
            var client = _clientFactory.GetProductCatalogClient();

            var query = new ProductQuery
            {
                SearchTerms = id,
                SearchField = ProductQuery.SearchFields.ProductId,
                Page = 1,
                PageSize = 1
            };

            var result = client.Search(query);

            if (result.TotalCount > 0)
                return MapProduct(result.Products[0]);

            throw new HttpResponseException(HttpStatusCode.NotFound);
        }
Exemplo n.º 3
0
        public List <Model.Entities.Product> GetProductList(ProductQuery query)
        {
            var products = ProductDao.Query();

            if (query == null)
            {
                query = new ProductQuery();
            }


            if (!string.IsNullOrWhiteSpace(query.ProductName))
            {
                products = products.Where(p => p.ProductName.Contains(query.ProductName.Trim()));
            }
            if (!string.IsNullOrWhiteSpace(query.BandName))
            {
                products = products.Where(p => p.BandName.Contains(query.BandName.Trim()));
            }

            products = products.OrderBy(m => m.CreatedOn).Skip(query.start).Take(query.length);
            return(products != null?products.ToList() : new List <Model.Entities.Product>());
        }
Exemplo n.º 4
0
        private void BindProducts()
        {
            ProductQuery query = new ProductQuery();

            query.Keywords   = keywords;
            query.CategoryId = categoryId;
            ;
            if (categoryId.HasValue)
            {
                query.MaiCategoryPath = SubsiteCatalogHelper.GetCategory(categoryId.Value).Path;
            }
            query.PageSize   = 10;
            query.PageIndex  = pager.PageIndex;
            query.SaleStatus = ProductSaleStatus.OnSale;
            query.SortOrder  = SortAction.Desc;
            query.SortBy     = "DisplaySequence";
            DbQueryResult products = SubSiteProducthelper.GetProducts(query);

            dlstProducts.DataSource = products.Data;
            dlstProducts.DataBind();
            pager.TotalRecords = products.TotalRecords;
        }
Exemplo n.º 5
0
        private void BindProducts()
        {
            ProductQuery query = new ProductQuery();

            query.Keywords   = txtSearchText.Text;
            query.CategoryId = dropCategories.SelectedValue;

            if (categoryId.HasValue)
            {
                query.MaiCategoryPath = CatalogHelper.GetCategory(categoryId.Value).Path;
            }
            query.PageSize   = 10;
            query.PageIndex  = pager.PageIndex;
            query.SaleStatus = ProductSaleStatus.OnSale;
            query.SortOrder  = SortAction.Desc;
            query.SortBy     = "DisplaySequence";
            DbQueryResult products = ProductHelper.GetProducts(query);

            dlstProducts.DataSource = products.Data;
            dlstProducts.DataBind();
            pager.TotalRecords = products.TotalRecords;
        }
Exemplo n.º 6
0
        private void BindProducts()
        {
            ProductQuery productQuery = new ProductQuery();

            productQuery.Keywords   = this.keywords;
            productQuery.CategoryId = this.categoryId;
            if (this.categoryId.HasValue)
            {
                productQuery.MaiCategoryPath = CatalogHelper.GetCategory(this.categoryId.Value).Path;
            }
            productQuery.PageSize   = 10;
            productQuery.PageIndex  = this.pager.PageIndex;
            productQuery.SaleStatus = ProductSaleStatus.OnSale;
            productQuery.SortOrder  = SortAction.Desc;
            productQuery.SortBy     = "DisplaySequence";
            productQuery.SupplierId = HiContext.Current.User.UserId;
            DbQueryResult products = ProductHelper.GetProducts(productQuery);

            this.dlstProducts.DataSource = products.Data;
            this.dlstProducts.DataBind();
            this.pager.TotalRecords = products.TotalRecords;
        }
Exemplo n.º 7
0
        protected override void AttachChildControls()
        {
            this.rptProducts    = (VshopTemplatedRepeater)this.FindControl("rptProducts");
            this.litdescription = (Literal)this.FindControl("litdescription");
            ProductQuery query = new ProductQuery();
            int          num   = 0;
            int          num2  = 0;

            if (!string.IsNullOrEmpty(this.Page.Request.QueryString["CategoryId"]) && !string.IsNullOrEmpty(this.Page.Request.QueryString["ActivitiesId"]))
            {
                if (!int.TryParse(this.Page.Request.QueryString["CategoryId"], out num))
                {
                    this.Page.Response.Redirect("Default.aspx");
                }
                else
                {
                    int.TryParse(this.Page.Request.QueryString["ActivitiesId"], out num2);
                    query.CategoryId = new int?(num);
                    DataTable activitie = ProductBrowser.GetActivitie(num2);
                    if (activitie.Rows.Count > 0)
                    {
                        this.litdescription.Text = activitie.Rows[0]["ActivitiesDescription"].ToString();
                        if ((this.rptProducts != null) && (query.CategoryId > 0))
                        {
                            query.PageSize  = 20;
                            query.PageIndex = 1;
                            DbQueryResult homeProduct = ProductBrowser.GetHomeProduct(MemberProcessor.GetCurrentMember(), query);
                            this.rptProducts.DataSource = homeProduct.Data;
                            this.rptProducts.DataBind();
                        }
                    }
                    else
                    {
                        this.Page.Response.Redirect("Default.aspx");
                    }
                }
            }
            PageTitle.AddSiteNameTitle("满减活动");
        }
Exemplo n.º 8
0
        public override DbQueryResult GetBatchBuyProducts(ProductQuery query)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("SaleStatus=1 AND DistributorUserId={0}", HiContext.Current.SiteSettings.UserId);
            if (!string.IsNullOrEmpty(query.Keywords))
            {
                query.Keywords = DataHelper.CleanSearchString(query.Keywords);
                string[] array = Regex.Split(query.Keywords.Trim(), "\\s+");
                stringBuilder.AppendFormat(" AND ProductName LIKE '%{0}%'", DataHelper.CleanSearchString(array[0]));
                int num = 1;
                while (num < array.Length && num <= 4)
                {
                    stringBuilder.AppendFormat("AND ProductName LIKE '%{0}%'", DataHelper.CleanSearchString(array[num]));
                    num++;
                }
            }
            if (query.CategoryId.HasValue && query.CategoryId.Value > 0)
            {
                stringBuilder.AppendFormat(" AND ( MainCategoryPath LIKE '{0}|%' OR ExtendCategoryPath LIKE '{0}|%')", query.MaiCategoryPath);
            }
            if (query.BrandId.HasValue)
            {
                stringBuilder.AppendFormat(" AND BrandId = {0}", query.BrandId.Value);
            }
            if (!string.IsNullOrEmpty(query.ProductCode))
            {
                stringBuilder.AppendFormat(" AND SKU LIKE '%{0}%'", DataHelper.CleanSearchString(query.ProductCode));
            }
            Member        member         = HiContext.Current.User as Member;
            int           memberDiscount = this.GetMemberDiscount(member.GradeId);
            StringBuilder stringBuilder2 = new StringBuilder();

            stringBuilder2.Append("SkuId, ProductId, SKU,ProductName, ThumbnailUrl40, DisplaySequence, Stock,");
            stringBuilder2.AppendFormat(" (CASE WHEN (SELECT COUNT(*) FROM distro_SKUMemberPrice WHERE SkuId = s.SkuId AND DistributoruserId = {0} AND GradeId = {1}) = 1", HiContext.Current.SiteSettings.UserId, member.GradeId);
            stringBuilder2.AppendFormat(" THEN (SELECT MemberSalePrice FROM distro_SKUMemberPrice WHERE SkuId = s.SkuId AND DistributoruserId = {0} AND GradeId = {1})", HiContext.Current.SiteSettings.UserId, member.GradeId);
            stringBuilder2.AppendFormat(" ELSE (SELECT SalePrice FROM vw_distro_SkuPrices WHERE SkuId = s.SkuId AND DistributoruserId = {0}) * {1} /100 END) AS SalePrice", HiContext.Current.SiteSettings.UserId, memberDiscount);
            return(DataHelper.PagingByRownumber(query.PageIndex, query.PageSize, query.SortBy, query.SortOrder, query.IsCount, "vw_distro_ProductSkuList s", "ProductId", stringBuilder.ToString(), stringBuilder2.ToString()));
        }
Exemplo n.º 9
0
        public void Products_Service_GetAllWithSize_ShouldBeOk()
        {
            //Arrange
            var product             = ObjectMother.GetProductValid();
            var size                = 1;
            var repositoryMockValue = new List <Product>()
            {
                product
            }.AsQueryable();
            var query = new ProductQuery(size);

            _productRepositoryFake.Setup(pr => pr.GetAll(query.Size)).Returns(repositoryMockValue);
            //Action
            var productResult = _service.GetAll(query);

            //Assert
            _productRepositoryFake.Verify(pr => pr.GetAll(query.Size), Times.Once);
            productResult.Should().NotBeNull();
            productResult.Count().Should().Be(repositoryMockValue.Count());
            //Perceba que Equals de Entity já compara os Id's
            productResult.First().Should().Be(repositoryMockValue.First());
        }
        public ProductQuery GetQuery()
        {
            var query = new ProductQuery
            {
                RevisionFilter = RevisionFilter,
                RecipeFilter   = RecipeFilter,
                Selector       = Selector,
                Revision       = Revision
            };

            if (!string.IsNullOrWhiteSpace(Identifier))
            {
                query.Identifier = Identifier;
            }

            if (!string.IsNullOrWhiteSpace(Name))
            {
                query.Name = Name;
            }

            return(query);
        }
        protected void DoCallback()
        {
            this.LoadParameters();
            ProductQuery query = new ProductQuery();

            query.PageSize   = this.pager.PageSize;
            query.PageIndex  = this.pager.PageIndex;
            query.SaleStatus = ProductSaleStatus.OnSale;
            query.Keywords   = this.productName;
            query.CategoryId = this.categoryId;
            if (this.categoryId.HasValue)
            {
                query.MaiCategoryPath = SubsiteCatalogHelper.GetCategory(this.categoryId.Value).Path;
            }
            query.IsIncludePromotionProduct = false;
            DbQueryResult products = SubSiteProducthelper.GetProducts(query);
            DataTable     data     = (DataTable)products.Data;

            this.pager1.TotalRecords       = this.pager.TotalRecords = products.TotalRecords;
            this.rp_bindproduct.DataSource = data;
            this.rp_bindproduct.DataBind();
        }
Exemplo n.º 12
0
        private void BindData()
        {
            ProductQuery entity = new ProductQuery();

            entity.PageSize      = pager.PageSize;
            entity.PageIndex     = pager.PageIndex;
            entity.ProductCode   = productCode;
            entity.Keywords      = productName;
            entity.ProductLineId = productLineId;
            if (grdAuthorizeProducts.SortOrder.ToLower() == "desc")
            {
                entity.SortOrder = SortAction.Desc;
            }
            entity.SortBy = grdAuthorizeProducts.SortOrderBy;
            Globals.EntityCoding(entity, true);
            DbQueryResult submitPuchaseProductsByDistorUserId = ProductHelper.GetSubmitPuchaseProductsByDistorUserId(entity, distorUserId);

            grdAuthorizeProducts.DataSource = submitPuchaseProductsByDistorUserId.Data;
            grdAuthorizeProducts.DataBind();
            pager.TotalRecords  = submitPuchaseProductsByDistorUserId.TotalRecords;
            pager1.TotalRecords = submitPuchaseProductsByDistorUserId.TotalRecords;
        }
Exemplo n.º 13
0
        private void BindData()
        {
            ProductQuery productQuery = new ProductQuery();

            productQuery.PageSize      = this.pager.PageSize;
            productQuery.PageIndex     = this.pager.PageIndex;
            productQuery.ProductCode   = this.productCode;
            productQuery.Keywords      = this.name;
            productQuery.ProductLineId = this.lineId;
            if (this.grdAuthorizeProducts.SortOrder.ToLower() == "desc")
            {
                productQuery.SortOrder = SortAction.Desc;
            }
            productQuery.SortBy = this.grdAuthorizeProducts.SortOrderBy;
            Globals.EntityCoding(productQuery, true);
            DbQueryResult authorizeProducts = SubSiteProducthelper.GetAuthorizeProducts(productQuery, false);

            this.grdAuthorizeProducts.DataSource = authorizeProducts.Data;
            this.grdAuthorizeProducts.DataBind();
            this.pager.TotalRecords  = authorizeProducts.TotalRecords;
            this.pager1.TotalRecords = authorizeProducts.TotalRecords;
        }
Exemplo n.º 14
0
        private void BindData()
        {
            ProductQuery productQuery = new ProductQuery();

            productQuery.PageSize      = this.pager.PageSize;
            productQuery.PageIndex     = this.pager.PageIndex;
            productQuery.ProductCode   = this.productCode;
            productQuery.Keywords      = this.productName;
            productQuery.ProductLineId = this.productLineId;
            if (this.grdAuthorizeProducts.SortOrder.ToLower() == "desc")
            {
                productQuery.SortOrder = SortAction.Desc;
            }
            productQuery.SortBy = this.grdAuthorizeProducts.SortOrderBy;
            Globals.EntityCoding(productQuery, true);
            DbQueryResult submitPuchaseProductsByDistorUserId = ProductHelper.GetSubmitPuchaseProductsByDistorUserId(productQuery, this.distorUserId);

            this.grdAuthorizeProducts.DataSource = submitPuchaseProductsByDistorUserId.Data;
            this.grdAuthorizeProducts.DataBind();
            this.pager.TotalRecords  = submitPuchaseProductsByDistorUserId.TotalRecords;
            this.pager1.TotalRecords = submitPuchaseProductsByDistorUserId.TotalRecords;
        }
Exemplo n.º 15
0
        private void DoCallback()
        {
            base.Response.Clear();
            base.Response.ContentType = "application/json";
            string text = base.Request.QueryString["action"];

            if (text.Equals("getGroupBuyProducts"))
            {
                ProductQuery productQuery = new ProductQuery();
                if (!string.IsNullOrEmpty(base.Request.QueryString["categoryId"]))
                {
                    int num = default(int);
                    int.TryParse(base.Request.QueryString["categoryId"], out num);
                    if (num > 0)
                    {
                        productQuery.CategoryId      = num;
                        productQuery.MaiCategoryPath = CatalogHelper.GetCategory(num).Path;
                    }
                }
                string productCode = base.Request.QueryString["sku"];
                string text3       = productQuery.Keywords = base.Request.QueryString["productName"];
                productQuery.ProductCode = productCode;
                productQuery.SaleStatus  = ProductSaleStatus.OnSale;
                DataTable groupBuyProducts = ProductHelper.GetGroupBuyProducts(productQuery);
                if (groupBuyProducts == null || groupBuyProducts.Rows.Count == 0)
                {
                    base.Response.Write("{\"Status\":\"0\"}");
                }
                else
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("{\"Status\":\"OK\",");
                    stringBuilder.AppendFormat("\"Product\":[{0}]", this.GenerateBrandString(groupBuyProducts));
                    stringBuilder.Append("}");
                    base.Response.Write(stringBuilder.ToString());
                }
            }
            base.Response.End();
        }
Exemplo n.º 16
0
        private void BindProducts()
        {
            this.LoadParameters();
            ProductQuery productQuery = new ProductQuery
            {
                Keywords          = this.productName,
                ProductCode       = this.productCode,
                CategoryId        = this.categoryId,
                ProductLineId     = this.lineId,
                PageSize          = this.pager.PageSize,
                PageIndex         = this.pager.PageIndex,
                SortOrder         = SortAction.Desc,
                SortBy            = "DisplaySequence",
                StartDate         = this.startDate,
                BrandId           = this.dropBrandList.SelectedValue.HasValue ? this.dropBrandList.SelectedValue : null,
                TagId             = this.dropTagList.SelectedValue.HasValue ? this.dropTagList.SelectedValue : null,
                TypeId            = this.typeId,
                UserId            = this.distributorId,
                IsAlert           = this.isAlert,
                SaleStatus        = this.saleStatus,
                PenetrationStatus = this.penetrationStatus,
                EndDate           = this.endDate
            };

            if (this.categoryId.HasValue)
            {
                productQuery.MaiCategoryPath = CatalogHelper.GetCategory(this.categoryId.Value).Path;
            }
            Globals.EntityCoding(productQuery, true);
            DbQueryResult shareProducts = ProductHelper.GetShareProducts(productQuery, false, this.shareId);

            this.rp_shareproduct.DataSource = shareProducts.Data;
            this.rp_shareproduct.DataBind();
            this.txtSearchText.Text           = productQuery.Keywords;
            this.dropCategories.SelectedValue = productQuery.CategoryId;
            this.dropType.SelectedValue       = productQuery.TypeId;
            this.chkIsAlert.Checked           = productQuery.IsAlert;
            this.pager1.TotalRecords          = (this.pager.TotalRecords = shareProducts.TotalRecords);
        }
Exemplo n.º 17
0
        public override void DataBind()
        {
            this.Items.Clear();
            ProductQuery query = new ProductQuery {
                Keywords    = this.productName,
                ProductCode = this.productCode,
                CategoryId  = this.categoryId,
                SaleStatus  = ProductSaleStatus.OnSale
            };

            if (this.categoryId.HasValue)
            {
                query.MaiCategoryPath = CatalogHelper.GetCategory(this.categoryId.Value).Path;
            }
            DataTable groupBuyProducts = ProductHelper.GetGroupBuyProducts(query);

            base.Items.Add(new ListItem("--请选择--", string.Empty));
            foreach (DataRow row in groupBuyProducts.Rows)
            {
                base.Items.Add(new ListItem(row["ProductName"].ToString(), row["ProductId"].ToString()));
            }
        }
Exemplo n.º 18
0
        public void SupplierDataBind(int?supplierId)
        {
            this.Items.Clear();
            ProductQuery productQuery = new ProductQuery();

            productQuery.Keywords    = this.productName;
            productQuery.ProductCode = this.productCode;
            productQuery.CategoryId  = this.categoryId;
            productQuery.SaleStatus  = ProductSaleStatus.OnSale;
            productQuery.SupplierId  = supplierId;
            if (this.categoryId.HasValue)
            {
                productQuery.MaiCategoryPath = CatalogHelper.GetCategory(this.categoryId.Value).Path;
            }
            DataTable groupBuyProducts = ProductHelper.GetGroupBuyProducts(productQuery);

            base.Items.Add(new ListItem("--请选择--", string.Empty));
            foreach (DataRow dataRow in groupBuyProducts.Rows)
            {
                base.Items.Add(new ListItem(dataRow["ProductName"].ToString(), dataRow["ProductId"].ToString()));
            }
        }
Exemplo n.º 19
0
        public JsonResult PageList_Products(int page, int rows, string productname)
        {
            ProductQuery productquery = new ProductQuery()
            {
                PageSize = rows, PageNo = page, ProductName = productname
            };
            PageModel <ProductInfo> products = ServiceHelper.Create <IProductService>().GetProducts(productquery);

            IEnumerable <ProductInfo> array = from item in products.Models.ToArray()
                                              select new ProductInfo
            {
                Id               = item.Id,
                ProductCode      = item.ProductCode,
                ProductName      = item.ProductName,
                EProductName     = item.EProductName,
                ShopId           = item.ShopId,
                ShopName         = (ServiceHelper.Create <IShopService>().GetShopName(item.ShopId) == null ? "" : ServiceHelper.Create <IShopService>().GetShopName(item.ShopId)),
                ShortDescription = item.ShortDescription,
                MarketPrice      = item.MarketPrice,
                Purity           = item.Purity,
                CASNo            = item.CASNo,
                HSCODE           = item.HSCODE,
                DangerLevel      = item.DangerLevel,
                MolecularFormula = item.MolecularFormula,
                ISCASNo          = item.ISCASNo,
                EditStatus       = item.EditStatus,
                MeasureUnit      = item.MeasureUnit,
                Quantity         = item.Quantity,
                Volume           = item.Volume,
                Weight           = item.Weight
            };
            DataGridModel <ProductInfo> dataGridModel = new DataGridModel <ProductInfo>()
            {
                rows  = array,
                total = products.Total
            };

            return(Json(dataGridModel));
        }
Exemplo n.º 20
0
        private void BindProducts()
        {
            this.LoadParameters();
            ProductQuery entity = new ProductQuery {
                wid         = this.wid,
                Keywords    = this.productName,
                ProductCode = this.productCode,
                CategoryId  = this.categoryId,
                PageSize    = this.pager.PageSize,
                PageIndex   = this.pager.PageIndex,
                SortOrder   = SortAction.Desc,
                SortBy      = "DisplaySequence",
                StartDate   = this.startDate,
                BrandId     = this.dropBrandList.SelectedValue.HasValue ? this.dropBrandList.SelectedValue : null,
                Stock       = 0,
                TypeId      = this.typeId,
                SaleStatus  = this.saleStatus,
                EndDate     = this.endDate
            };

            if (this.categoryId.HasValue && (this.categoryId > 0))
            {
                entity.MaiCategoryPath = CatalogHelper.GetCategory(this.categoryId.Value).Path;
            }
            Globals.EntityCoding(entity, true);
            DbQueryResult products = ProductHelper.GetProducts(entity);

            this.grdProducts.DataSource = products.Data;
            this.grdProducts.DataBind();
            this.txtSearchText.Text           = entity.Keywords;
            this.txtSKU.Text                  = entity.ProductCode;
            this.dropCategories.SelectedValue = entity.CategoryId;
            DataTable productNum = ProductHelper.GetProductNum(this.wid);

            this.LitOnSale.Text     = "出售中(" + productNum.Rows[0]["OnSale"].ToString() + ")";
            this.LitOnStock.Text    = "仓库中(" + productNum.Rows[0]["OnStock"].ToString() + ")";
            this.LitZero.Text       = "已售罄(" + productNum.Rows[0]["Zero"].ToString() + ")";
            this.pager.TotalRecords = products.TotalRecords;
        }
Exemplo n.º 21
0
        public async Task <QueryResult <Product> > GetProductsAsync(ProductQuery queryObj)
        {
            var result = new QueryResult <Product>();

            var query = entities.Include(p => p.Category).AsQueryable();

            query = query.ApplyFiltering(queryObj);

            var columnsMap = new Dictionary <string, Expression <Func <Product, object> > >()
            {
                ["name"] = p => p.Name
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query        = query.ApplyPaging(queryObj);
            result.Items = await query.ToListAsync();

            return(result);
        }
Exemplo n.º 22
0
        public int countProduct(ProductQuery productQuery)
        {
            var products = ProductDao.Query();

            if (productQuery == null)
            {
                productQuery = new ProductQuery();
            }

            if (!string.IsNullOrWhiteSpace(productQuery.ProductName))
            {
                products = products.Where(p => p.ProductName.Contains(productQuery.ProductName));
            }
            if (!string.IsNullOrWhiteSpace(productQuery.BandName))
            {
                products = products.Where(p => p.BandName.Contains(productQuery.BandName));
            }

            int count = products.Count();

            return(count);
        }
Exemplo n.º 23
0
    void BindSearchs()
    {
        string query = Request.QueryString["w"];

        query = HttpUtility.UrlDecode(query);
        TextBox txt = sMain.FindControl("txtSearch") as TextBox;

        if (txt != null)
        {
            if (!string.IsNullOrEmpty(query))
            {
                txt.Text = query;
            }
        }

        ProductQuery pq = new ProductQuery();

        pq.ProductNameFilter = query;
        pq.PageSize          = Int32.MaxValue;
        ucpProducts.IsSearch = true;
        ucpProducts.Query    = pq;
    }
Exemplo n.º 24
0
        public async Task <PagedResult <ProductDto> > GetProductsPagedAsync(ProductQuery query)
        {
            var page     = query.Page;
            var pageSize = query.PageSize;

            // Filter

            var linqQuery = _context.Products
                            .Where(x => x.Name.Contains(query.Name));


            var count = await linqQuery.CountAsync();

            var totalPages = (int)Math.Ceiling(count / (double)pageSize);

            if (page < 1)
            {
                page = 1;
            }

            if (totalPages == 0)
            {
                totalPages = 1;
            }

            if (page > totalPages)
            {
                page = totalPages;
            }

            var results = await linqQuery
                          .Skip((page - 1) *pageSize)
                          .Take(pageSize)
                          .ToListAsync();

            var resultsDto = _mapper.Map <IEnumerable <Product>, IEnumerable <ProductDto> >(results);

            return(new PagedResult <ProductDto>(resultsDto, count, page, pageSize, totalPages));
        }
        private void BindData()
        {
            ProductQuery entity = new ProductQuery();

            entity.PageSize      = this.pager.PageSize;
            entity.PageIndex     = this.pager.PageIndex;
            entity.ProductCode   = this.productCode;
            entity.Keywords      = this.productName;
            entity.ProductLineId = this.productLineId;
            if (this.grdAuthorizeProducts.SortOrder.ToLower() == "desc")
            {
                entity.SortOrder = SortAction.Desc;
            }
            entity.SortBy = this.grdAuthorizeProducts.SortOrderBy;
            Globals.EntityCoding(entity, true);
            DbQueryResult submitPuchaseProducts = SubSiteProducthelper.GetSubmitPuchaseProducts(entity);

            this.grdAuthorizeProducts.DataSource = submitPuchaseProducts.Data;
            this.grdAuthorizeProducts.DataBind();
            this.pager.TotalRecords  = submitPuchaseProducts.TotalRecords;
            this.pager1.TotalRecords = submitPuchaseProducts.TotalRecords;
        }
Exemplo n.º 26
0
        public StringBuilder GetProductView(ProductQuery query, string localhost, string strformat, string skucontentformat, out int recordes)
        {
            StringBuilder builder         = new StringBuilder();
            int           totalrecord     = 0;
            DataSet       productsByQuery = ProductHelper.GetProductsByQuery(query, out totalrecord);
            StringBuilder builder2        = new StringBuilder();

            foreach (DataRow row in productsByQuery.Tables[0].Rows)
            {
                string str = "false";
                foreach (DataRow row2 in row.GetChildRows("ProductRealation"))
                {
                    str = "true";
                    string skuContent = MessageInfo.GetSkuContent(row2["SkuId"].ToString());
                    builder2.AppendFormat(skucontentformat, new object[] { row2["ProductId"].ToString(), row2["SKuId"].ToString(), skuContent, row2["Stock"].ToString(), row2["SalePrice"].ToString() });
                }
                string str3 = localhost + Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { row["ProductId"].ToString() });
                builder.AppendFormat(strformat, new object[] { row["ProductId"].ToString(), row["ProductCode"].ToString(), row["ProductName"].ToString(), localhost + row["ThumbnailUrl60"].ToString(), str3, row["MarketPrice"].ToString(), row["SalePrice"].ToString(), row["Weight"].ToString(), row["SaleStatus"].ToString(), str, builder2 });
            }
            recordes = totalrecord;
            return(builder);
        }
Exemplo n.º 27
0
        public DbQueryResult GetHomeProducts(MemberInfo member, ProductQuery query)
        {
            int           discount             = 100;
            StringBuilder builder              = new StringBuilder();
            int           currentDistributorId = Globals.GetCurrentDistributorId();

            builder.Append("p.ProductId, ProductCode,ShortDescription,ProductName,ShowSaleCounts, ThumbnailUrl60,ThumbnailUrl40,ThumbnailUrl100,ThumbnailUrl180,ThumbnailUrl220,ThumbnailUrl310, MarketPrice,");
            if (member != null)
            {
                discount = new MemberGradeDao().GetMemberGrade(member.GradeId).Discount;
                builder.AppendFormat(" (CASE WHEN (SELECT COUNT(*) FROM Hishop_SKUMemberPrice WHERE SkuId = p.SkuId AND GradeId = {0}) = 1", member.GradeId);
                builder.AppendFormat(" THEN (SELECT MemberSalePrice FROM Hishop_SKUMemberPrice WHERE SkuId = p.SkuId AND GradeId = {0}) ELSE SalePrice*{1}/100 END) AS SalePrice, ", member.GradeId, discount);
            }
            else
            {
                builder.Append("SalePrice,");
            }
            builder.Append("SaleCounts, Stock");
            StringBuilder builder2 = new StringBuilder(" SaleStatus =" + 1);

            return(DataHelper.PagingByRownumber(query.PageIndex, query.PageSize, query.SortBy, query.SortOrder, query.IsCount, "vw_Hishop_BrowseProductList p inner join  Vshop_HomeProducts t on p.productid=t.ProductId ", "p.ProductId", builder2.ToString(), builder.ToString()));
        }
Exemplo n.º 28
0
        public void TestMethod1()
        {
            var products = new List <Product>
            {
                new Product {
                    Name = "01", Amount = 10, Actived = false, Category = new Category {
                        Actived = false
                    }
                },
                new Product {
                    Name = "02", Amount = 11, Actived = false, Category = new Category {
                        Actived = false
                    }
                },
                new Product {
                    Name = "03", Amount = 8, Actived = true, Category = new Category {
                        Actived = true
                    }
                },
                new Product {
                    Name = "04", Amount = 5, Actived = true, Category = new Category {
                        Actived = true
                    }
                },
                new Product {
                    Name = "05", Amount = 4, Actived = false, Category = new Category {
                        Actived = true
                    }
                }
            };

            var productQuery = new ProductQuery();

            foreach (var product in productQuery.ExecuteQuery(products.AsQueryable()).ToList())
            {
                Console.WriteLine(product.Name);
            }
        }
Exemplo n.º 29
0
        public IEnumerable <API.Resource.Product> getProducts(ProductQuery query, out int total)
        {
            Expression <Func <DB.Models.Product, bool> > queryAsExpre = query.asExpression();
            IQueryable <DB.Models.Product> productQuery = _context.Product
                                                          .Include(p => p.Brand)
                                                          .Include(p => p.ChannelProduct)
                                                          .ThenInclude(cp => cp.Channel)
                                                          .Include(p => p.ProductType)
                                                          .Include(p => p.RelatedProduct)
                                                          .Include(p => p.RelatedProductNavigation)
                                                          .Include(p => p.VendorProduct)
                                                          .ThenInclude(vp => vp.Vendor)
                                                          .Include(p => p.ProductAttributeOption)
                                                          .ThenInclude(pao => pao.AttributeOption)
                                                          .ThenInclude(pao => pao.Attribute)
                                                          .ThenInclude(pao => pao.AttributeType)
                                                          .Include(p => p.ProductAttributeValue)
                                                          .ThenInclude(pao => pao.Attribute)
                                                          .ThenInclude(pao => pao.AttributeType)
                                                          .Include(p => p.ParentProduct)
                                                          .Where <DB.Models.Product>(queryAsExpre);
            IQueryable <DB.Models.Product> newQuery = query.getOrdering(productQuery);
            List <DB.Models.Product>       products = newQuery
                                                      .Skip(query.page * query.results)
                                                      .Take(query.results)
                                                      .ToList();

            total = productQuery.Count();

            List <API.Resource.Product> retList = new List <Resource.Product>();

            foreach (DB.Models.Product prod in products)
            {
                API.Resource.Product newprod = mapper.Map <API.Resource.Product>(prod);
                retList.Add(newprod);
            }
            return(retList);
        }
Exemplo n.º 30
0
        private void BindProducts()
        {
            this.LoadParameters();
            ProductQuery productQuery = new ProductQuery();

            productQuery.PageSize   = this.pager.PageSize;
            productQuery.PageIndex  = this.pager.PageIndex;
            productQuery.Keywords   = this.txtProductName.Text;
            productQuery.BrandId    = this.dropBrandCategories.SelectedValue;
            productQuery.CategoryId = this.ddlCategories.SelectedValue;
            if (productQuery.CategoryId.HasValue)
            {
                productQuery.MaiCategoryPath = CategoryBrowser.GetCategory(productQuery.CategoryId.Value).Path;
            }
            productQuery.SortOrder = SortAction.Desc;
            productQuery.SortBy    = "DisplaySequence";
            Globals.EntityCoding(productQuery, true);
            DbQueryResult batchBuyProducts = ProductBrowser.GetBatchBuyProducts(productQuery);

            this.batchbuys.DataSource = batchBuyProducts.Data;
            this.batchbuys.DataBind();
            this.pager.TotalRecords = batchBuyProducts.TotalRecords;
        }
        public void ThenTheResultIsAsExpected()
        {
            var query = new ProductQuery {
                CreatedBy = "user1"
            };
            var pageInfo = new PageInfo(
                2,
                2,
                new OrderBy(ProductRepository.CREATED_BY_COLUMN, Order.DESCENDING));
            var actual = _sut.PagedQuery(pageInfo, query);

            // Simulate the paging on the in-memory collection.
            var expected = _products.OrderByDescending(x => x.CreatedBy).Skip(2).Take(2).ToList();

            Assert.AreEqual(pageInfo, actual.PageInfo);
            Assert.AreEqual(5, actual.TotalCount);
            Assert.AreEqual(2, actual.Result.Count());
            foreach (var item in expected)
            {
                var actualDto = actual.Result.Single(x => x.Id == item.Id);
                Assert.AreEqual(item, actualDto);
            }
        }
Exemplo n.º 32
0
        private void LoadProducts()
        {
            DataModel.ProductQuery q = new ProductQuery();
            q.Where(q.StoreId == StoreContext.CurrentStore.Id).OrderBy(q.Name.Ascending);

            ProductCollection products = new ProductCollection();

            if (products.Load(q))
            {
                var relatedProductIds = product.RelatedProductCollectionByProductId.Select(p => Convert.ToString(p.RelatedProductId.Value));

                cblRelatedProducts.DataSource     = products;
                cblRelatedProducts.DataTextField  = "Name";
                cblRelatedProducts.DataValueField = "Id";

                cblRelatedProducts.DataBind();

                foreach (ListItem p in cblRelatedProducts.Items)
                {
                    p.Selected = relatedProductIds.Contains(p.Value);
                }
            }
        }
Exemplo n.º 33
0
        public static SearchResult GetByProductIds(this IProductCatalog client, params string[] productIds)
        {
            if (productIds == null)
                throw new ArgumentNullException("productIds");

            if (productIds.Length == 0)
                return new SearchResult
                {
                    TotalCount = 0,
                    Products = new Product[] { }
                };

            var products = productIds
                .Chunk(10)
                .SelectMany
                (
                    chunk =>
                    {
                        var query = new ProductQuery
                        {
                            Page = 1,
                            PageSize = int.MaxValue,
                            SearchTerms = string.Join(" ", chunk.ToArray()),
                            SearchField = ProductQuery.SearchFields.ProductId
                        };

                        return client.Search(query).Products;
                    }
                )
                .ToArray();

            return new SearchResult
            {
                TotalCount = products.Length,
                Products = products
            };
        }
        public void DownloadProducts(string catID, string brandFilterID, string retailerFilterID,string priceFilterID, string discountFilterID)
        {
            ProductQuery query = new ProductQuery();

            if(!string.IsNullOrEmpty(catID))
                query.withCategory(catID); // Category jackets
            if(!string.IsNullOrEmpty(brandFilterID))
                query.withFilter(brandFilterID); // Brand filter id
            if(!string.IsNullOrEmpty(retailerFilterID))
                query.withFilter(retailerFilterID);// Retailer filter id
            if (!string.IsNullOrEmpty(priceFilterID))
                query.withFilter(priceFilterID); // Price filter id
            if (!string.IsNullOrEmpty(discountFilterID))
                query.withFilter(discountFilterID); // Discount filter id

            var productResponse = api.getProducts(query);

            ProductSearchMetadata metadata = productResponse.getMetadata();
            int total = metadata.getTotal(); // pageCounter = total/limit, these three values are being used to calculate paging.
            int limit = metadata.getLimit();
            int offset = metadata.getOffset();

            foreach (var product in productResponse.getProducts())
            {
                using (CatalogDataContext dc = new CatalogDataContext())
                {
                    if (dc.SS_Products.FirstOrDefault(x => x.product_id == product.getId()) != null)
                    {
                        continue;
                    }
                }

                using (CatalogDataContext dc = new CatalogDataContext())
                {
                    SS_Product ssProduct = new SS_Product()
                    {
                        id = System.Guid.NewGuid(),
                        brand_id = (int?)product.getBrand().getId(),
                        click_url = product.getClickUrl(),
                        currency = product.getCurrency().getCurrencyCode(),
                        description = product.getDescription(),
                        image_id = product.getImage().getId(),
                        in_stock = product.isInStock(),
                        locale = product.getLocale().getDisplayCountry(),
                        name = product.getName(),
                        price = (decimal?)product.getPrice(),
                        price_label = product.getPriceLabel(),
                        retailer_id = (int?)product.getRetailer().getId(),
                        product_id = (int)product.getId(),
                        sale_price = (decimal?)product.getSalePrice() == 0 ? null : (decimal?)product.getSalePrice(),
                        sale_price_label = product.getSalePriceLabel()
                    };
                    dc.SS_Products.InsertOnSubmit(ssProduct);
                    dc.SubmitChanges();

                    foreach (ImageSize imageSize in product.getImage().getSizes().values().toArray())
                    {
                        using (CatalogDataContext dc1 = new CatalogDataContext())
                        {
                            SS_Image image = new SS_Image()
                            {
                                id = System.Guid.NewGuid(),
                                size_name = imageSize.getSizeName().toString(),
                                image_id = ssProduct.image_id,
                                url = imageSize.getUrl(),
                                height = imageSize.getHeight(),
                                width = imageSize.getWidth()
                            };
                            dc1.SS_Images.InsertOnSubmit(image);
                            dc1.SubmitChanges();

                        }
                    }

                }

                //Insert categories and product-category mapping records
                foreach (var category in product.getCategories())
                {
                    using (CatalogDataContext dc = new CatalogDataContext())
                    {
                        SS_Product ssProduct = dc.SS_Products.FirstOrDefault(x => x.product_id == product.getId());

                        if (ssProduct != null)
                        {
                            SS_Product_Category_Mapping pcMapping = new SS_Product_Category_Mapping() { id = System.Guid.NewGuid(), product_id = ssProduct.product_id, cat_id = category.getId() };
                            dc.SS_Product_Category_Mappings.InsertOnSubmit(pcMapping);
                            dc.SubmitChanges();
                        }
                        else
                        {
                            throw new ArgumentNullException("Could not find the newly inserted product");
                        }

                    }

                }

                //Isert product_color_image_mapping records
                foreach (var color in product.getColors())
                {
                    using (CatalogDataContext dc = new CatalogDataContext())
                    {
                        SS_Product_Color_Image_Mapping pciMapping = new SS_Product_Color_Image_Mapping()
                        {
                            id = System.Guid.NewGuid(),
                            color_name = color.getName(),
                            image_id = color.getImage().getId(),
                            product_id = (int)product.getId()
                        };

                        foreach (ImageSize imageSize in color.getImage().getSizes().values().toArray())
                        {
                            using (CatalogDataContext dc1 = new CatalogDataContext())
                            {
                                if (dc1.SS_Images.FirstOrDefault(x => x.image_id == pciMapping.image_id) == null)
                                {
                                    SS_Image image = new SS_Image()
                                    {
                                        id = System.Guid.NewGuid(),
                                        size_name = imageSize.getSizeName().toString(),
                                        image_id = pciMapping.image_id,
                                        url = imageSize.getUrl(),
                                        height = imageSize.getHeight(),
                                        width = imageSize.getWidth()
                                    };
                                    dc1.SS_Images.InsertOnSubmit(image);
                                    dc1.SubmitChanges();
                                }
                            }
                        }

                        dc.SS_Product_Color_Image_Mappings.InsertOnSubmit(pciMapping);
                        dc.SubmitChanges();
                    }

                }

                //Insert size and product_size_mapping
                foreach (var size in product.getSizes())
                {
                    using (CatalogDataContext dc = new CatalogDataContext())
                    {
                        SS_Size result = dc.SS_Sizes.FirstOrDefault(x => x.name == size.getName());

                        if (result == null)
                        {
                            System.Guid sizeId;
                            using (CatalogDataContext dc1 = new CatalogDataContext())
                            {
                                SS_Size s = new SS_Size() { id = System.Guid.NewGuid(), name = size.getName() };
                                dc1.SS_Sizes.InsertOnSubmit(s);
                                dc1.SubmitChanges();

                                sizeId = s.id;
                            }

                            using (CatalogDataContext dc2 = new CatalogDataContext())
                            {
                                SS_Product_Size_Mapping psMapping = new SS_Product_Size_Mapping() { id = System.Guid.NewGuid(), product_id = (int)product.getId(), size_id = sizeId };
                                dc2.SS_Product_Size_Mappings.InsertOnSubmit(psMapping);
                                dc2.SubmitChanges();
                            }

                        }
                        else
                        {
                            SS_Product_Size_Mapping psMapping = new SS_Product_Size_Mapping() { id = System.Guid.NewGuid(), product_id = (int)product.getId(), size_id = result.id };
                            dc.SS_Product_Size_Mappings.InsertOnSubmit(psMapping);
                            dc.SubmitChanges();
                        }
                    }
                }
            }
        }
        public void DownloadProducts(string fts, string catID, string brandFilterID, string retailerFilterID, string priceFilterID, string discountFilterID, string productSetName)
        {
            ProductQuery query = new ProductQuery();
            if (!string.IsNullOrEmpty(fts))
                query.withFreeText(fts);
            if (!string.IsNullOrEmpty(catID))
                query.withCategory(catID); // Category jackets
            if (!string.IsNullOrEmpty(brandFilterID))
                query.withFilter(brandFilterID); // Brand filter id
            if (!string.IsNullOrEmpty(retailerFilterID))
                query.withFilter(retailerFilterID);// Retailer filter id
            if (!string.IsNullOrEmpty(priceFilterID))
                query.withFilter(priceFilterID); // Price filter id
            if (!string.IsNullOrEmpty(discountFilterID))
                query.withFilter(discountFilterID); // Discount filter id

            var response = api.getProducts(query);

            ProductSearchMetadata metadata = response.getMetadata();
            int total = metadata.getTotal(); // pageCounter = total/limit, these three values are being used to calculate paging.
            int limit = metadata.getLimit();
            int offset = metadata.getOffset();
            int pageCount = (int)Math.Ceiling((double)total / 100);

            System.Guid productSetID;

            using (CatalogDataContext context = new CatalogDataContext())
            {
                var ps = (from set in context.SS_Product_Sets where set.product_set_name == productSetName select set).SingleOrDefault();
                if (ps == null)
                {
                    SS_Product_Set productSet = new SS_Product_Set()
                    {
                        id = System.Guid.NewGuid(),
                        product_set_name = productSetName,
                        tb_seller_cid = ProductService.AddSellerCat(productSetName).Cid,
                        datetimecreated = (DateTime?)DateTime.Now
                    };

                    context.SS_Product_Sets.InsertOnSubmit(productSet);
                    context.SubmitChanges();
                    productSetID = productSet.id;
                }
                else
                    productSetID = ps.id;

            }

            for (int i = 0; i < pageCount; i++)
            {
                PageRequest page = new PageRequest().withLimit(100).withOffset(offset);
                var productResponse = api.getProducts(query, page, ProductSort.PriceLoHi);

                foreach (var product in productResponse.getProducts())
                {
                    try
                    {
                         using (CatalogDataContext dc = new CatalogDataContext())
                    {
                        if (dc.SS_Products.FirstOrDefault(x => x.product_id == product.getId()) != null)
                        {
                            continue;
                        }
                    }

                    using (CatalogDataContext dc = new CatalogDataContext())
                    {

                        SS_Product ssProduct = new SS_Product()
                        {
                            id = System.Guid.NewGuid(),
                            brand_id = (int?)product.getBrand().getId(),
                            click_url = product.getClickUrl(),
                            currency = product.getCurrency().getCurrencyCode(),
                            description = product.getDescription(),
                            chinese_description = getTranslateResult(stripOffHTMLTags(product.getDescription()), true) ?? string.Empty,
                            image_id = product.getImage().getId(),
                            in_stock = product.isInStock(),
                            locale = product.getLocale().getDisplayCountry(),
                            name = product.getName(),
                            chinese_name = product.getBrand().getName() + getTranslateResult(product.getName(), false) ?? string.Empty,
                            price = (decimal?)product.getPrice(),
                            price_label = product.getPriceLabel(),
                            retailer_id = (int?)product.getRetailer().getId(),
                            product_id = (int)product.getId(),
                            sale_price = (decimal?)product.getSalePrice() == 0 ? null : (decimal?)product.getSalePrice(),
                            sale_price_label = product.getSalePriceLabel(),
                            istranslated = false,
                            keyword = fts,
                            datetimecreated = DateTime.Now,
                            product_set_name_id = productSetID
                        };
                        dc.SS_Products.InsertOnSubmit(ssProduct);
                        dc.SubmitChanges();

                    }

                    using (CatalogDataContext dc = new CatalogDataContext())
                    {
                        SS_Product ssProduct = dc.SS_Products.FirstOrDefault(x => x.product_id == product.getId());

                        //Insert categories and product-category mapping records
                        if (!string.IsNullOrEmpty(catID))
                        {
                            SS_Product_Category_Mapping pcMapping = new SS_Product_Category_Mapping() { id = System.Guid.NewGuid(), product_id = ssProduct.product_id, cat_id = catID };
                            dc.SS_Product_Category_Mappings.InsertOnSubmit(pcMapping);
                            dc.SubmitChanges();
                        }
                        else
                        {
                            foreach (var category in product.getCategories())
                            {
                                if (ssProduct != null)
                                {
                                    SS_Product_Category_Mapping pcMapping = new SS_Product_Category_Mapping() { id = System.Guid.NewGuid(), product_id = ssProduct.product_id, cat_id = category.getId() };
                                    dc.SS_Product_Category_Mappings.InsertOnSubmit(pcMapping);
                                    dc.SubmitChanges();
                                }
                                else
                                {
                                    throw new ArgumentNullException("Could not find the newly inserted product");
                                }
                            }
                        }
                    }

                    //insert main image
                    foreach (ImageSize imageSize in product.getImage().getSizes().values().toArray())
                    {
                        using (CatalogDataContext dc1 = new CatalogDataContext())
                        {
                            SS_Product ssProduct = dc1.SS_Products.FirstOrDefault(x => x.product_id == product.getId());

                            SS_Image image = new SS_Image()
                            {
                                id = System.Guid.NewGuid(),
                                size_name = imageSize.getSizeName().toString(),
                                image_id = ssProduct.image_id,
                                url = imageSize.getUrl(),
                                height = imageSize.getHeight(),
                                width = imageSize.getWidth()
                            };
                            dc1.SS_Images.InsertOnSubmit(image);
                            dc1.SubmitChanges();

                        }
                    }

                    //Isert product_color_image_mapping records
                    foreach (var color in product.getColors())
                    {
                        using (CatalogDataContext dc = new CatalogDataContext())
                        {

                            SS_Product ssProduct = dc.SS_Products.FirstOrDefault(x => x.product_id == product.getId());

                            SS_Product_Color_Image_Mapping pciMapping = new SS_Product_Color_Image_Mapping();
                            pciMapping.id = System.Guid.NewGuid();
                            pciMapping.color_name = color.getName();
                            pciMapping.product_id = (int)product.getId();

                            if (color.getImage() == null)
                            {
                                pciMapping.image_id = ssProduct.image_id;//if there's no image element inside color element, that means only one color available.
                            }
                            else
                            {
                                pciMapping.image_id = color.getImage().getId();
                            }

                            if (color.getImage() != null)
                            {
                                var ssImage = (from image in dc.SS_Images where image.image_id == color.getImage().getId() select image).FirstOrDefault();

                                if (ssImage == null)
                                {
                                    foreach (ImageSize imageSize in color.getImage().getSizes().values().toArray())
                                    {
                                        using (CatalogDataContext dc1 = new CatalogDataContext())
                                        {

                                            SS_Image image = new SS_Image()
                                            {
                                                id = System.Guid.NewGuid(),
                                                size_name = imageSize.getSizeName().toString(),
                                                image_id = pciMapping.image_id,
                                                url = imageSize.getUrl(),
                                                height = imageSize.getHeight(),
                                                width = imageSize.getWidth()
                                            };
                                            dc1.SS_Images.InsertOnSubmit(image);
                                            dc1.SubmitChanges();

                                        }
                                    }
                                }
                            }

                            dc.SS_Product_Color_Image_Mappings.InsertOnSubmit(pciMapping);
                            dc.SubmitChanges();
                        }

                    }

                    //Insert size and product_size_mapping
                    foreach (var size in product.getSizes())
                    {
                        using (CatalogDataContext dc = new CatalogDataContext())
                        {
                            SS_Size result = dc.SS_Sizes.FirstOrDefault(x => x.name == size.getName());

                            if (result == null)
                            {
                                System.Guid sizeId;
                                using (CatalogDataContext dc1 = new CatalogDataContext())
                                {
                                    SS_Size s = new SS_Size() { id = System.Guid.NewGuid(), name = size.getName() };
                                    dc1.SS_Sizes.InsertOnSubmit(s);
                                    dc1.SubmitChanges();

                                    sizeId = s.id;
                                }

                                using (CatalogDataContext dc2 = new CatalogDataContext())
                                {
                                    SS_Product_Size_Mapping psMapping = new SS_Product_Size_Mapping() { id = System.Guid.NewGuid(), product_id = (int)product.getId(), size_id = sizeId };
                                    dc2.SS_Product_Size_Mappings.InsertOnSubmit(psMapping);
                                    dc2.SubmitChanges();
                                }

                            }
                            else
                            {
                                SS_Product_Size_Mapping psMapping = new SS_Product_Size_Mapping() { id = System.Guid.NewGuid(), product_id = (int)product.getId(), size_id = result.id };
                                dc.SS_Product_Size_Mappings.InsertOnSubmit(psMapping);
                                dc.SubmitChanges();
                            }
                        }
                    }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                offset += 100;
            }
        }
        /// <summary>
        /// This method returns List<SS_Price> and List<SS_Discount> which are used 
        /// as datasource in DownloadSetting.asmx page. So the end user could
        /// select price range and discount range. Call this method before calling
        /// DownloadProduct method.
        /// </summary>
        /// <param name="catID"></param>
        /// <param name="brandFilterID"></param>
        /// <param name="retailerFilterID"></param>
        /// <param name="dscList"></param>
        /// <returns></returns>
        public List<SS_Price> GetPriceAndDiscountRange(string catID, string brandFilterID, string retailerFilterID, out List<SS_Discount> dscList)
        {
            ProductQuery query = new ProductQuery();
            List<SS_Price> pList = new List<SS_Price>();
            dscList = new List<SS_Discount>();

            if (!string.IsNullOrEmpty(catID))
                query.withCategory(catID); // Category jackets
            if (!string.IsNullOrEmpty(brandFilterID))
                query.withFilter(brandFilterID); // Brand filter id
            if (!string.IsNullOrEmpty(retailerFilterID))
                query.withFilter(retailerFilterID);// Retailer filter id

            var priceResponse = api.getProductsHistogram(query, typeof(Price));
            var discountResponse = api.getProductsHistogram(query, typeof(Discount));

            if (priceResponse.getPriceHistogram() != null)
            {
                foreach (var p in priceResponse.getPriceHistogram())
                {
                    pList.Add(new SS_Price() { FilterID = p.getPrice().getFilterId(), Name = p.getPrice().getName(), URL = p.getPrice().getUrl() });
                }
            }
            if (discountResponse.getDiscountHistogram() != null)
            {
                foreach (var d in discountResponse.getDiscountHistogram())
                {
                    dscList.Add(new SS_Discount() { FilterID = d.getDiscount().getFilterId(), Name = d.getDiscount().getName(), URL = d.getDiscount().getUrl() });
                }
            }

            return pList;
        }
        public List<Product> SearcProducts(string fts, string catId, string brandFilterID, string retailerFilterID,
            string priceFilterId, string discountFilterId, string productSetName)
        {
            var query = new ProductQuery();
            if (!string.IsNullOrEmpty(fts))
                query.withFreeText(fts);
            if (!string.IsNullOrEmpty(catId))
                query.withCategory(catId); // Category jackets
            if (!string.IsNullOrEmpty(brandFilterID))
                query.withFilter(brandFilterID); // Brand filter id
            if (!string.IsNullOrEmpty(retailerFilterID))
                query.withFilter(retailerFilterID);// Retailer filter id
            if (!string.IsNullOrEmpty(priceFilterId))
                query.withFilter(priceFilterId); // Price filter id
            if (!string.IsNullOrEmpty(discountFilterId))
                query.withFilter(discountFilterId); // Discount filter id

            var response = api.getProducts(query);
            ProductSearchMetadata metadata = response.getMetadata();
            int total = metadata.getTotal(); // pageCounter = total/limit, these three values are being used to calculate paging.
            int limit = metadata.getLimit();
            int offset = metadata.getOffset();
            int pageCount = (int)Math.Ceiling((double)total / 100);
            var list = new List<Product>();
            for (int i = 0; i < pageCount; i++)
            {
                PageRequest page = new PageRequest().withLimit(100).withOffset(offset);
                var productResponse = api.getProducts(query, page, ProductSort.PriceLoHi);
                list.AddRange(productResponse.getProducts());
            }
            return list;
        }
        /// <summary>
        /// This method returns List<Price> and List<Discount> which are used 
        /// as datasource in DownloadSetting.asmx page. So the end user could
        /// select price range and discount range. Call this method before calling
        /// DownloadProduct method.
        /// </summary>
        /// <param name="catID"></param>
        /// <param name="brandFilterID"></param>
        /// <param name="retailerFilterID"></param>
        /// <param name="dscList"></param>
        /// <returns></returns>
        public List<Price> GetPriceAndDiscountRange(string catID, string brandFilterID,string retailerFilterID,out List<Discount> dscList)
        {
            ProductQuery query = new ProductQuery();
            List<Price> pList = new List<Price>();
            dscList = new List<Discount>();

            if (!string.IsNullOrEmpty(catID))
                query.withCategory(catID); // Category jackets
            if (!string.IsNullOrEmpty(brandFilterID))
                query.withFilter(brandFilterID); // Brand filter id
            if (!string.IsNullOrEmpty(retailerFilterID))
                query.withFilter(retailerFilterID);// Retailer filter id

                var histogramResponse = api.getProductsHistogram(query, typeof(Price), typeof(Discount));

                if (histogramResponse.getPriceHistogram() != null)
                {
                    foreach (var p in histogramResponse.getPriceHistogram())
                    {
                        pList.Add(p.getPrice());
                    }
                }
                if (histogramResponse.getDiscountHistogram() != null)
                {
                    foreach (var d in histogramResponse.getDiscountHistogram())
                    {
                        dscList.Add(d.getDiscount());
                    }
                }

            return pList;
        }
Exemplo n.º 39
0
        public static void GetProductHistogram()
        {
            ShopStyle api = new ShopStyle("uid8409-24047347-36", ShopStyle.UK_API_HOSTNAME);

            CatalogDataContext dc = new CatalogDataContext();
            SS_Category ssCat = dc.SS_Categories.FirstOrDefault<SS_Category>(c => c.cat_id == "jackets");
            SS_Brand ssBrand = dc.SS_Brands.FirstOrDefault<SS_Brand>(b => b.brand_id == 870);
            SS_Retailer ssRetailer = dc.SS_Retailers.FirstOrDefault<SS_Retailer>(r => r.retailer_id == 274);

            ProductQuery query = new ProductQuery().withCategory("jackets");
            Category cat = new Category(ssCat.cat_id, ssCat.name, ssCat.parentid);
            Brand brand = new Brand(ssBrand.brand_id,ssBrand.brand_name,ssBrand.url);
            Retailer retailer = new Retailer(ssRetailer.retailer_id,ssRetailer.name,ssRetailer.url,true);

            query.withCategory(cat); // Category jackets
            //query.withFilter(brand); // Brand filter id
            //query.withFilter(retailer);// Retailer filter id

            //SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            //java.util.Date parsed = format.parse("20130810");
            //java.sql.Date pdd = new java.sql.Date(parsed.getTime());

            //query.withPriceDropDate(pdd);

            ProductHistogramResponse response = api.getProductsHistogram(query,typeof(Price),typeof(Discount));

            PriceHistogramEntry[] arrPriHisEntry = response.getPriceHistogram();
        }
Exemplo n.º 40
0
        public dynamic Search(
            string q   = null, // search terms. product name, partid or display partid
            string cat = null, // category name. NOTE: this is an english value
            int i      = 1,    // page number
            int s      = 5,    // page size
            bool? cdsf = null, // cds free filter
            bool? cdsp = null  // cds paid filter
        )
        {
            var today = DateTime.Now.Date;
            var client = _clientFactory.GetProductCatalogClient();

            var query = new ProductQuery
            {
                SearchTerms               = q,
                CategoryName              = cat,
                SearchField               = ProductQuery.SearchFields.LimitedFields,
                IsCDSFree                 = cdsf,
                IsCDSPaid                 = cdsp,
                MaxConsultantStartDateUtc = today,
                MinExpirationDateUtc      = today.AddYears(_appSettings.GetValue<int>("ProductCatalog.MinExpirationDateUtc.YearOffset")),
                Page                      = i,
                PageSize                  = s
            };

            var currentCulture = Thread.CurrentThread.CurrentUICulture;
            try
            {
                var result = client.Search(query);

                return new
                {
                    totalCount = result.TotalCount,
                    products   = result.Products.Select(MapProduct).ToArray()
                };
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = currentCulture;
            }
        }
        Product[] GetProductDetails(IProductCatalog client, IEnumerable<string> productIds)
        {
            if (productIds == null)
                throw new ArgumentNullException("productIds");

            if (!productIds.Any())
                return new Product[] { };

            var products = productIds
                .Chunk(10)
                .SelectMany
                (
                    chunk =>
                    {
                        var query = new ProductQuery
                        {
                            Page        = 1,
                            PageSize    = int.MaxValue,
                            SearchTerms = string.Join(" ", chunk.ToArray()),
                            SearchField = ProductQuery.SearchFields.ProductId
                        };

                        return client.Search(query).Products;
                    }
                )
                .ToArray();

            return products;
        }
Exemplo n.º 42
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        // get product sku from querystring
        if (Request.Params["sku"] != null)
        {
            SKU = Request.Params["sku"];
        }

        // get product num # from querystring
        if (Request.QueryString["product_num"] != null)
        {
            _productNum = Request.QueryString["product_num"];
        }

        // get quantity from querystring
        if (Request.Params["quantity"] != null)
        {
            if (!int.TryParse(Request.Params["quantity"],out _quantity))
            {
                _quantity = 1;
            }
        }

        if (SKU.Length == 0 && _productNum.Length == 0)
        {
            Response.Redirect("~/error.aspx");
            return;
        }

        if (!Page.IsPostBack)
        {
            ZNodeSKU productSKU = new ZNodeSKU();

            if (SKU.Length > 0)
            {
                productSKU = ZNodeSKU.CreateBySKU(SKU);

                if (productSKU.SKUID == 0)
                {
                    ProductService productService = new ProductService();
                    ProductQuery filters = new ProductQuery();
                    filters.AppendEquals(ProductColumn.SKU, SKU);
                    TList<Product> productList = productService.Find(filters.GetParameters());

                    if (productList != null)
                    {
                        if (productList.Count == 0)
                        {
                            // If SKUID or Invalid SKU is Zero then Redirected to default page
                            Response.Redirect("~/error.aspx");
                        }
                    }
                    else
                    {
                        // If SKUID or Invalid SKU is Zero then Redirected to default page
                        Response.Redirect("~/error.aspx");
                    }

                    ProductID = productList[0].ProductID;

                    _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID);
                }
                else
                {
                    // If SKU parameter is supplied & it has value
                    ProductID = productSKU.ProductID;

                    _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID);

                    // Set product SKU
                    _product.SelectedSKU = productSKU;
                }
            }
            else if (_productNum.Length > 0)
            {
                ProductService productService = new ProductService();
                ProductQuery filters = new ProductQuery();
                filters.AppendEquals(ProductColumn.ProductNum, _productNum);
                TList<Product> productList = productService.Find(filters.GetParameters());

                if (productList != null)
                {
                    if (productList.Count == 0)
                    {
                        // If SKUID or Invalid SKU is Zero then Redirected to default page
                        Response.Redirect("~/error.aspx");
                    }
                }
                else
                {
                    // If SKUID or Invalid SKU is Zero then Redirected to default page
                    Response.Redirect("~/error.aspx");
                }

                ProductID = productList[0].ProductID;

                _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID);
            }
            else
            {
                // If SKUID or Invalid SKU is Zero then Redirected to default page
                Response.Redirect("~/error.aspx");
            }

            // Check product attributes count
            if (_product.ZNodeAttributeTypeCollection.Count > 0 && productSKU.SKUID == 0)
            {
                Response.Redirect(_product.ViewProductLink);
            }

            // Loop through the product addons
            foreach (ZNodeAddOn _addOn in _product.ZNodeAddOnCollection)
            {
                if (!_addOn.OptionalInd)
                {
                    Response.Redirect(_product.ViewProductLink);
                }
            }

            // Create shopping cart item
            ZNodeShoppingCartItem item = new ZNodeShoppingCartItem();
            item.Product = new ZNodeProductBase(_product);
            item.Quantity = _quantity;

            // Add product to cart
            ZNodeShoppingCart shoppingCart = ZNodeShoppingCart.CurrentShoppingCart();

            // If shopping cart is null, create in session
            if (shoppingCart == null)
            {
                shoppingCart = new ZNodeShoppingCart();
                shoppingCart.AddToSession(ZNodeSessionKeyType.ShoppingCart);
            }

            // add item to cart
            if (shoppingCart.AddToCart(item))
            {
                string link = "~/shoppingcart.aspx";
                Response.Redirect(link);
            }
            else
            {
                // If Product is out of Stock - Redirected to Product Details  page
                Response.Redirect("~/error.aspx");
            }
        }
    }