Esempio n. 1
0
        /// <summary>
        /// Save new brand to the database , return the new brand with new Id
        /// </summary>
        /// <param name="newBrand"> the new brand model </param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static BrandModel AddBrandToTheDatabase(BrandModel newBrand, string db)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
            {
                var p = new DynamicParameters();
                p.Add("@BrandName", newBrand.Name);



                p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
                connection.Execute("dbo.spBrand_Create", p, commandType: CommandType.StoredProcedure);
                newBrand.Id = p.Get <int>("@Id");
            }
            return(newBrand);
        }
Esempio n. 2
0
        /// <summary>
        /// Filter list of stocks by category and brand of the products in the stock list
        /// </summary>
        /// <param name="stocks"> list of stock model </param>
        /// <param name="category"> category model </param>
        /// <param name="defaultCategoryId">the default product id const value signed in the database</param>
        /// <param name="brand">brand model</param>
        /// <param name="defaultBrandId">the default product id const value signed in the database</param>
        /// <returns> list of filterd stocks by category and brand</returns>
        public static List <StockModel> FilterStocksByCategoryAndBrand(List <StockModel> stocks, CategoryModel category, int defaultCategoryId, BrandModel brand, int defaultBrandId)
        {
            List <StockModel> FStocks = new List <StockModel>();

            bool FilterByBrand    = true;
            bool FilterByCategory = true;

            if (brand == null || brand.Id == defaultBrandId)
            {
                FilterByBrand = false;
            }

            if (category == null || category.Id == defaultCategoryId)
            {
                FilterByCategory = false;
            }

            // Filter by Brand and category
            if (FilterByBrand == true && FilterByCategory == true)
            {
                foreach (StockModel stock in stocks)
                {
                    if (stock.Product.Category.Id == category.Id && stock.Product.Brand.Id == brand.Id)
                    {
                        FStocks.Add(stock);
                    }
                }
                return(FStocks);
            }

            // Filter by category Only
            else if (FilterByBrand == false && FilterByCategory == true)
            {
                foreach (StockModel stock in stocks)
                {
                    if (stock.Product.Category.Id == category.Id)
                    {
                        FStocks.Add(stock);
                    }
                }
                return(FStocks);
            }

            // Filter by brand Only
            else if (FilterByBrand == true && FilterByCategory == false)
            {
                foreach (StockModel stock in stocks)
                {
                    if (stock.Product.Brand.Id == brand.Id)
                    {
                        FStocks.Add(stock);
                    }
                }
                return(FStocks);
            }

            // No Filtering
            else
            {
                return(stocks);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Filter The given products with the categories and brands
        /// </summary>
        /// <param name="products"></param>
        /// <param name="category"></param>
        /// <param name="brand"></param>
        /// <returns></returns>
        public static List <ProductModel> FilterProductsByCategoryAndBrand(List <ProductModel> products, CategoryModel category, BrandModel brand)
        {
            List <ProductModel> FProducts = new List <ProductModel>();
            bool FilterByBrand            = true;
            bool FilterByCategory         = true;

            if (brand == null || brand == PublicVariables.DefaultBrand)
            {
                FilterByBrand = false;
            }

            if (category == null || category == PublicVariables.DefaultCategory)
            {
                FilterByCategory = false;
            }



            // Filter by Brand and category
            if (FilterByBrand == true && FilterByCategory == true)
            {
                return(FProducts = products.FindAll(x => x.Brand == brand && x.Category == category));
            }

            // Filter by category Only
            else if (FilterByBrand == false && FilterByCategory == true)
            {
                return(FProducts = products.FindAll(x => x.Category == category));
            }

            // Filter by brand Only
            else if (FilterByBrand == true && FilterByCategory == false)
            {
                return(FProducts = products.FindAll(x => x.Brand == brand));
            }

            // No Filtering
            else
            {
                return(products);
            }
        }