Пример #1
0
        public List <Product_Cart> getProductCartsByEmail(string email)
        {
            List <Product_Cart> result = new List <Product_Cart>();
            string        sql          = "SELECT * FROM Product_Cart WHERE Email = N'" + email + "'";
            SqlDataReader reader       = DataProvider.ExecuteQueryWithDataReader(sql, CommandType.Text);

            while (reader.Read())
            {
                int        productId  = reader.GetInt32(1);
                ProductDAL productDal = new ProductDAL();
                Product    product    = productDal.getProductById(productId);

                Product_Cart productCart = new Product_Cart()
                {
                    Email      = reader.GetString(0),
                    Product_ID = reader.GetInt32(1),
                    Quantity   = reader.GetInt32(2),
                    Product    = product,
                };

                result.Add(productCart);
            }
            reader.Close();
            return(result);
        }
        public void getProductsByCatalogue(Catalogue catalogue, int quantity)
        {
            String sql = "SELECT *"
                         + " FROM Product"
                         + " WHERE Catalogue_ID = " + catalogue.Catalogue_ID;
            List <Product> products = new List <Product>();

            try
            {
                SqlDataReader reader = DataProvider.ExecuteQueryWithDataReader(sql, CommandType.Text);
                while (reader.Read())
                {
                    Product product = new Product
                    {
                        Product_ID            = reader.GetInt32(0),
                        Catalogue_ID          = reader.GetInt32(1),
                        Is_Sale               = reader.GetBoolean(2),
                        Product_Name          = reader.GetString(3),
                        Price                 = reader.GetFloat(4),
                        Level_Trending        = reader.GetInt32(5),
                        Description           = reader.GetString(6),
                        Products_Available    = reader.GetInt32(7),
                        Total_Sold            = reader.GetInt32(8),
                        Created_Date          = reader.GetDateTime(9),
                        Created_Username      = reader.GetString(10),
                        Guarantee_Description = reader.GetString(11),
                        Title_Image           = reader.GetString(12),
                        Tax_Percent           = reader.GetFloat(13),
                        Manufacturer          = reader.GetString(14),
                    };
                    ProductDAL productDal = new ProductDAL();
                    productDal.getAllPromotions(product);
                    products.Add(product);
                }
                var random       = new Random();
                var shuffledList = products.OrderBy(item => random.Next());
                int count        = 0;
                foreach (var item in shuffledList)
                {
                    catalogue.Products.Add(item);
                    count++;
                    if (count >= quantity)
                    {
                        break;
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public void getAllProductsByCatalogue(Catalogue catalogue)
        {
            String sql = "SELECT *"
                         + " FROM Product"
                         + " WHERE Catalogue_ID = " + catalogue.Catalogue_ID;

            try
            {
                SqlDataReader reader = DataProvider.ExecuteQueryWithDataReader(sql, CommandType.Text);
                while (reader.Read())
                {
                    Product product = new Product
                    {
                        Product_ID            = reader.GetInt32(0),
                        Catalogue_ID          = reader.GetInt32(1),
                        Is_Sale               = reader.GetBoolean(2),
                        Product_Name          = reader.GetString(3),
                        Price                 = reader.GetFloat(4),
                        Level_Trending        = reader.GetInt32(5),
                        Description           = reader.GetString(6),
                        Products_Available    = reader.GetInt32(7),
                        Total_Sold            = reader.GetInt32(8),
                        Created_Date          = reader.GetDateTime(9),
                        Created_Username      = reader.GetString(10),
                        Guarantee_Description = reader.GetString(11),
                        Title_Image           = reader.GetString(12),
                        Tax_Percent           = reader.GetFloat(13),
                        Manufacturer          = reader.GetString(14),
                    };
                    ProductDAL productDal = new ProductDAL();
                    productDal.getAllPromotions(product);
                    catalogue.Products.Add(product);
                }
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
        }