public static IEnumerable<Product> GetProductsIncludeHidden()
        {
            var products = new List<Product>();
            using (var connection = new SqlConnection(GetConnection()))
            {

                var sql = @"SELECT * FROM [dbo].[products]";
                var cmd = new SqlCommand(sql, connection);

                connection.Open();
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var product = new Product
                        {
                            Id = reader.GetInt32(0),
                            Code = reader.GetString(1),
                            Name = reader.GetString(2),
                            AddedDate = reader.GetDateTime(3),
                            ModifiedDate = reader.IsDBNull(4) ? null : (DateTime?)reader.GetDateTime(4),
                            Price = reader.GetSqlMoney(5).ToDouble(),
                            CategoryId = reader.GetInt32(6),
                            Hidden = reader.GetBoolean(7)
                        };

                        products.Add(product);
                    }
                }
                return products;
            }
        }
 private object ConvertToProductDTO(Product product, IEnumerable<CategoryManagement.Category> categories)
 {
     return new ProductDTO
         {
             ProductId = product.Id,
             Code = product.Code,
             DateAdded = product.AddedDate.ToString("dd/MM/yyyy"),
             Name = product.Name,
             LastModifiedDate =
                 product.ModifiedDate == null ? "" : product.ModifiedDate.Value.ToString("dd/MM/yyyy"),
             Price = Convert.ToDecimal(product.Price),
             Category = categories.Single(c => c.Id == product.CategoryId).Name,
             Hidden = product.Hidden
         };
 }
        /// <summary>
        /// Get all Products
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IEnumerable<Product> GetProducts(ProductType type)
        {
            var products = new List<Product>();
            using (var connection = new SqlConnection(GetConnection()))
            {

                var sql = @"SELECT * FROM [dbo].[products] WHERE hidden = 0";
                if (type != ProductType.All)
                {
                    sql += " AND categoriesID = @t";
                }
                var cmd = new SqlCommand(sql, connection);

                connection.Open();
                if (type != ProductType.All)
                {
                    cmd.Parameters
                     .Add(new SqlParameter("@t", SqlDbType.Int))
                     .Value = (int)type;
                }

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var product = new Product
                        {
                            Id = reader.GetInt32(0),
                            Code = reader.GetString(1),
                            Name = reader.GetString(2),
                            AddedDate = reader.GetDateTime(3),
                            ModifiedDate = reader.IsDBNull(4) ? null : (DateTime?)reader.GetDateTime(4),
                            Price = reader.GetSqlMoney(5).ToDouble(),
                            CategoryId = reader.GetInt32(6)
                        };

                        products.Add(product);
                    }
                }
                return products;
            }
        }