Beispiel #1
0
 public List <Product> GetAllProduct(ProductAdvanceSearch productAdvanceSearch)
 {
     return(_productRepository.GetAllProduct(productAdvanceSearch));
 }
        public List <Product> GetAllProduct(ProductAdvanceSearch productAdvanceSearch)
        {
            List <Product> productList = 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].[GetAllProduct]";
                        cmd.Parameters.Add("@SearchValue", SqlDbType.NVarChar, -1).Value = string.IsNullOrEmpty(productAdvanceSearch.SearchTerm) ? "" : productAdvanceSearch.SearchTerm;
                        cmd.Parameters.Add("@RowStart", SqlDbType.Int).Value             = productAdvanceSearch.DataTablePaging.Start;
                        if (productAdvanceSearch.DataTablePaging.Length == -1)
                        {
                            cmd.Parameters.AddWithValue("@Length", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.Add("@Length", SqlDbType.Int).Value = productAdvanceSearch.DataTablePaging.Length;
                        }
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            if ((sdr != null) && (sdr.HasRows))
                            {
                                productList = new List <Product>();
                                while (sdr.Read())
                                {
                                    Product product = new Product();
                                    {
                                        product.ID                          = (sdr["ID"].ToString() != "" ? Guid.Parse(sdr["ID"].ToString()) : product.ID);
                                        product.Code                        = (sdr["Code"].ToString() != "" ? sdr["Code"].ToString() : product.Code);
                                        product.Name                        = (sdr["Name"].ToString() != "" ? sdr["Name"].ToString() : product.Name);
                                        product.ProductCategory             = new ProductCategory();
                                        product.ProductCategory.Description = (sdr["Category"].ToString() != "" ? (sdr["Category"].ToString()) : product.ProductCategory.Description);
                                        product.IntroducedDate              = (sdr["IntroducedDate"].ToString() != "" ? DateTime.Parse(sdr["IntroducedDate"].ToString()) : product.IntroducedDate);
                                        product.IntroducedDateFormatted     = (sdr["IntroducedDate"].ToString() != "" ? DateTime.Parse(sdr["IntroducedDate"].ToString()).ToString(_settings.DateFormat) : product.IntroducedDateFormatted);
                                        product.Company                     = new Company();
                                        product.Company.Name                = (sdr["CompanyName"].ToString() != "" ? (sdr["CompanyName"].ToString()) : product.Company.Name);
                                        product.HSNCode                     = (sdr["HSNCode"].ToString() != "" ? sdr["HSNCode"].ToString() : product.HSNCode);
                                        product.Purpose                     = (sdr["Purpose"].ToString() != "" ? sdr["Purpose"].ToString() : product.Purpose);
                                        product.TotalCount                  = (sdr["TotalCount"].ToString() != "" ? int.Parse(sdr["TotalCount"].ToString()) : product.TotalCount);
                                        product.FilteredCount               = (sdr["FilteredCount"].ToString() != "" ? int.Parse(sdr["FilteredCount"].ToString()) : product.FilteredCount);
                                    }
                                    productList.Add(product);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(productList);
        }