Beispiel #1
0
 public IActionResult GetStyleProductList(SearchProductListModel searchModel)
 {
     try
     {
         string scheme = this.Request.Scheme;
         scheme += "://" + this.Request.Host + this.Request.PathBase;
         StyleCampaignList styleCampaignList = new StyleCampaignList();
         if (searchModel.pageNo <= 0)
         {
             searchModel.pageNo = 1;
         }
         styleCampaignList = iStyleCampaign.GetStyleCampaignList(DBHelper.ParseString((int)ProductCategoryEnum.Styles), searchModel.searchString, searchModel.pageNo, searchModel.limit, searchModel.CategoryTypeId, scheme, searchModel.column, searchModel.direction);
         if (styleCampaignList != null)
         {
             return(Ok(ResponseHelper.Success(styleCampaignList)));
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.DataNotFound)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
        /// <summary>
        /// Gets the style campaign list.
        /// </summary>
        /// <param name="productCategoryId">The product category identifier.</param>
        /// <param name="searchText">The search text.</param>
        /// <param name="pageNo">The page no.</param>
        /// <param name="recordPerPage">The record per page.</param>
        /// <param name="productCategoryTypeId">The product category type identifier.</param>
        /// <param name="hostingPath">The hosting path.</param>
        /// <param name="column">The column.</param>
        /// <param name="direction">The direction.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public StyleCampaignList GetStyleCampaignList(string productCategoryId, string searchText, int pageNo, int recordPerPage, string productCategoryTypeId, string hostingPath, string column, string direction)
        {
            StyleCampaignList styleCampaignListModel = new StyleCampaignList();

            try
            {
                SqlParameter[] parameters = new SqlParameter[7];
                parameters[0] = new SqlParameter("PRODUCTCATEGORYID", productCategoryId);
                parameters[1] = new SqlParameter("SEARCHSTRING", searchText);
                parameters[2] = new SqlParameter("PAGENO", pageNo);
                parameters[3] = new SqlParameter("RECORDPERPAGE", recordPerPage);
                parameters[4] = new SqlParameter("PRODUCTCATEGORYTYPEID", productCategoryTypeId);
                parameters[5] = new SqlParameter("COLUMN", column);
                parameters[6] = new SqlParameter("DIRECTION", direction);
                DataSet dataSet = DBHelper.GetDataTable("GETPRODUCTSLIST", parameters, DBHelper.ParseString(settings.Value.AppDbContext));
                if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count > 0)
                {
                    DataTable dtProduct         = dataSet.Tables[0];
                    DataTable dtCategory        = dataSet.Tables[1];
                    DataTable dtProductCategory = dataSet.Tables[2];
                    DataTable dtTotal           = dataSet.Tables[3];
                    DataTable dtPopular         = new DataTable();
                    if (dataSet.Tables.Count > 4)
                    {
                        dtPopular = dataSet.Tables[4];
                    }
                    List <StyleCampaignProductList> ProductList         = new List <StyleCampaignProductList>();
                    List <ProductCategoryListModel> productCategoryList = new List <ProductCategoryListModel>();
                    if (dtProduct != null && dtProduct.Rows.Count > 0)
                    {
                        if (dtPopular == null || dtPopular.Rows.Count <= 0)
                        {
                            foreach (DataRow item in dtProduct.Rows)
                            {
                                string    category   = string.Empty;
                                DataRow[] drCategory = dtProductCategory.Select("ProductFK='" + DBHelper.ParseString(item["ProductId"]) + "'");
                                if (drCategory != null && drCategory.Length > 0)
                                {
                                    foreach (var cat in drCategory)
                                    {
                                        category += DBHelper.ParseString(cat["CategoryType"]) + ",";
                                    }
                                    category = category.TrimEnd(',');
                                }

                                string image = string.Empty;
                                if (!string.IsNullOrWhiteSpace(DBHelper.ParseString(item["Image"])))
                                {
                                    image = hostingPath + Constants.ProductImagesPath.Replace(@"\", "/") + "/" + DBHelper.ParseString(item["Image"]);
                                }
                                else
                                {
                                    image = hostingPath + Constants.NoImageAvaliablePath.Replace(@"\", "/");
                                }
                                ProductList.Add(new StyleCampaignProductList
                                {
                                    Category       = category,
                                    Image          = image,
                                    Price          = DBHelper.ParseString(item["Price"]),
                                    ProductId      = DBHelper.ParseString(item["ProductId"]),
                                    ProductName    = DBHelper.ParseString(item["ProductName"]),
                                    ProductColorId = DBHelper.ParseString(item["ProductColorId"]),
                                });
                            }
                        }
                        else
                        {
                            foreach (DataRow popular in dtProduct.Rows)
                            {
                                DataRow[] item = dtProduct.Select("ProductId='" + popular["ProductId"] + "'");
                                if (item != null && item.Length > 0)
                                {
                                    string    category   = string.Empty;
                                    DataRow[] drCategory = dtProductCategory.Select("ProductFK='" + DBHelper.ParseString(item[0]["ProductId"]) + "'");
                                    if (drCategory != null && drCategory.Length > 0)
                                    {
                                        foreach (var cat in drCategory)
                                        {
                                            category += DBHelper.ParseString(cat["CategoryType"]) + ",";
                                        }
                                        category = category.TrimEnd(',');
                                    }

                                    string image = string.Empty;
                                    if (!string.IsNullOrWhiteSpace(DBHelper.ParseString(item[0]["Image"])))
                                    {
                                        image = hostingPath + Constants.ProductImagesPath.Replace(@"\", "/") + "/" + DBHelper.ParseString(item[0]["Image"]);
                                    }
                                    else
                                    {
                                        image = hostingPath + Constants.NoImageAvaliablePath.Replace(@"\", "/");
                                    }
                                    ProductList.Add(new StyleCampaignProductList
                                    {
                                        Category       = category,
                                        Image          = image,
                                        Price          = DBHelper.ParseString(item[0]["Price"]),
                                        ProductId      = DBHelper.ParseString(item[0]["ProductId"]),
                                        ProductName    = DBHelper.ParseString(item[0]["ProductName"]),
                                        ProductColorId = DBHelper.ParseString(item[0]["ProductColorId"]),
                                    });
                                }
                            }
                        }
                    }
                    if (dtCategory != null && dtCategory.Rows.Count > 0)
                    {
                        foreach (DataRow item in dtCategory.Rows)
                        {
                            productCategoryList.Add(new ProductCategoryListModel
                            {
                                Name = DBHelper.ParseString(item["CategoryType"]),
                                ProductCategoryId = DBHelper.ParseInt64(DBHelper.ParseString(item["ProductCategoryTypeId"]))
                            });
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(productCategoryTypeId))
                    {
                        string[] splitted = productCategoryTypeId.Split(',');
                        if (splitted != null && splitted.Length > 0)
                        {
                            DataRow[] drfind = dtCategory.Select("ProductCategoryTypeId='" + splitted[0] + "'");
                            if (drfind != null && drfind.Length > 0)
                            {
                                StyleCampaignDetailModel campaignDetailModel = new StyleCampaignDetailModel();
                                campaignDetailModel.CampaignId   = DBHelper.ParseString(drfind[0]["ProductCategoryTypeId"]);
                                campaignDetailModel.CampaignName = DBHelper.ParseString(drfind[0]["CategoryType"]);
                                string image = string.Empty;
                                if (string.IsNullOrWhiteSpace(DBHelper.ParseString(drfind[0]["Image"])))
                                {
                                    image = hostingPath + "/" + Constants.NoImageAvaliablePath.Replace(@"\", "/");
                                }
                                else
                                {
                                    image = hostingPath + Constants.ProductCategoryTypeImagesPath.Replace(@"\", "/") + "/" + DBHelper.ParseString(drfind[0]["Image"]);
                                }
                                campaignDetailModel.CampaignImage    = image;
                                styleCampaignListModel.CampaignModel = campaignDetailModel;
                            }
                        }
                    }
                    styleCampaignListModel.ProductLists  = ProductList;
                    styleCampaignListModel.CategoryList  = productCategoryList;
                    styleCampaignListModel.TotalProducts = DBHelper.ParseString(dtTotal.Rows.Count);
                    return(styleCampaignListModel);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
                throw ex;
            }
        }