Beispiel #1
0
        public List <ProductCategory> GetAllProductCategory(ProductCategoryAdvanceSearch productCategoryAdvanceSearch)
        {
            List <ProductCategory> productCategoryList = null;

            try
            {
                using (SqlConnection con = _databaseFactory.GetDBConnection())
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        if (con.State == ConnectionState.Closed)
                        {
                            con.Open();
                        }
                        cmd.Connection  = con;
                        cmd.CommandText = "[PSA].[GetAllProductCategory]";
                        cmd.Parameters.Add("@SearchValue", SqlDbType.NVarChar, -1).Value = string.IsNullOrEmpty(productCategoryAdvanceSearch.SearchTerm)?"": productCategoryAdvanceSearch.SearchTerm;
                        cmd.Parameters.Add("@RowStart", SqlDbType.Int).Value             = productCategoryAdvanceSearch.DataTablePaging.Start;
                        if (productCategoryAdvanceSearch.DataTablePaging.Length == -1)
                        {
                            cmd.Parameters.AddWithValue("@Length", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.Add("@Length", SqlDbType.Int).Value = productCategoryAdvanceSearch.DataTablePaging.Length;
                        }
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            if ((sdr != null) && (sdr.HasRows))
                            {
                                productCategoryList = new List <ProductCategory>();
                                while (sdr.Read())
                                {
                                    ProductCategory productCategory = new ProductCategory();
                                    {
                                        productCategory.Code         = (sdr["Code"].ToString() != "" ? int.Parse(sdr["Code"].ToString()) : productCategory.Code);
                                        productCategory.Description  = (sdr["Description"].ToString() != "" ? sdr["Description"].ToString() : productCategory.Description);
                                        productCategory.PSASysCommon = new PSASysCommon();
                                        productCategory.PSASysCommon.CreatedDateString = (sdr["CreatedDate"].ToString() != "" ? DateTime.Parse(sdr["CreatedDate"].ToString()).ToString(settings.DateFormat) : productCategory.PSASysCommon.CreatedDateString);
                                        productCategory.TotalCount    = (sdr["TotalCount"].ToString() != "" ? int.Parse(sdr["TotalCount"].ToString()) : productCategory.TotalCount);
                                        productCategory.FilteredCount = (sdr["FilteredCount"].ToString() != "" ? int.Parse(sdr["FilteredCount"].ToString()) : productCategory.FilteredCount);
                                    }
                                    productCategoryList.Add(productCategory);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(productCategoryList);
        }
 public List <ProductCategory> GetAllProductCategory(ProductCategoryAdvanceSearch productCategoryAdvanceSearch)
 {
     return(_productCategoryRepository.GetAllProductCategory(productCategoryAdvanceSearch));
 }