Esempio n. 1
0
        public ActionResult ByCategory()
        {
            ProductsByCategoryViewModel model = new ProductsByCategoryViewModel();

            model.Category = "All";

            IEnumerable <Product> products = db.Products.Where(s => s.StocksQuantity > 0);

            model.Products = products;

            return(View(model));
        }
        public ActionResult List(string subAlias, ProductOperationViewModel vm)
        {
            var category = _unitOfWork.Categories.GetByAlias(subAlias);

            var products = _unitOfWork.Products.GetProductsByCategory(category.Id, vm.Name, vm.PriceFrom, vm.PriceTo, vm.Limit);

            var sortedProducts = _unitOfWork.Products.Sort(products, vm.Field, vm.Sort);

            var wishListId = _unitOfWork.WishLists.GetWishListId(HttpContext);

            var areProductsAtWishList = new Dictionary <int, bool>();

            foreach (var product in products)
            {
                var check = product.WishLists.Any(w => w.ProductId == product.Id && w.WishListId == wishListId);
                areProductsAtWishList.Add(product.Id, check);
            }

            var model = new ProductsByCategoryViewModel()
            {
                Products = sortedProducts,
                Category = category,
                AreProductsAtWishList = areProductsAtWishList
            };

            if (Request.IsAjaxRequest())
            {
                if (vm.Grid == "grid")
                {
                    return(View("ProductsGrid", model));
                }

                return(View("ProductsLarge", model));
            }

            return(View(model));
        }
Esempio n. 3
0
        public ActionResult ByCategory(List <string> categories)
        {
            IEnumerable <Product> products = null;

            foreach (var category in categories)
            {
                if (products == null)
                {
                    // initate Enterprises
                    products = db.Products.Where(p => p.Category == category);
                }
                else
                {
                    /// just do the concat
                    products = products.Concat(db.Products.Where(p => p.Category == category));
                }
            }

            ProductsByCategoryViewModel model = new ProductsByCategoryViewModel();

            model.Products = products.Where(s => s.StocksQuantity > 0);
            model.Category = categories.ToString();
            return(View(model));
        }
Esempio n. 4
0
        private ProductsByCategoryViewModel GetProductsByCategories(int posId)
        {
            var con = new System.Data.SqlClient.SqlConnection(MySettings.ConnectionStringDefault);

            con.Open();
            var cmd = new System.Data.SqlClient.SqlCommand(
                @"select 
--    top 1000
    p.id as id,             -- 0
    p.internal_code, 
    p.uid, 
    p.name, 
    p.price, 
	c.id as category_id,    -- 5
    c.name as category_name,
	isnull(pd.parameter_value, '') as size_name, 
    isnull(pd.price_minor, 0) as price_minor, 
    isnull(pd.price_release_minor, 0) as price_release_minor, 
    isnull(pd.quantity, 0),             -- 10
    isnull(pd.id, 0) as price_id,
    isnull(pd.data_json, '') as data_json
from product p
	join category c on p.category_id = c.id
	left join product_detail pd on p.id = pd.product_id
where p.pos_id = " + posId + @"
order by p.id", con);

            ProductsByCategoryViewModel productsByCategories = new ProductsByCategoryViewModel();
            var     products = new List <OnBalance.Domain.Entities.Product>();
            decimal priceMinor, priceReleaseMinor;
            int     priceId;
            string  dataJson;
            Dictionary <int, string> categoryNames = new Dictionary <int, string>();

            var r = cmd.ExecuteReader();

            while (r.Read())
            {
                var p = new Product();
                p.Id           = r.GetInt32(0);
                p.InternalCode = r.GetString(1);
                p.Uid          = r.GetString(2);
                p.Name         = r.GetString(3);
                //p.Price = r.GetDecimal(4);
                p.CategoryId      = r.GetInt32(5);
                p.Price           = r.GetDecimal(9);
                priceMinor        = r.GetDecimal(8);
                priceReleaseMinor = r.GetDecimal(9);
                var psq = new ProductSizeQuantity();
                psq.SizeName = r.GetString(7);
                psq.Quantity = r.GetInt32(10);
                priceId      = r.GetInt32(11);
                dataJson     = r.GetString(12);

                // Store category name
                categoryNames[p.CategoryId] = r.GetString(6);

                var existing = products.FirstOrDefault(x => x.Id == p.Id);
                if (existing == null)
                {
                    var newP = new Domain.Entities.Product
                    {
                        Id           = p.Id,
                        InternalCode = p.InternalCode,
                        Uid          = p.Uid,
                        Name         = p.Name,
                        CategoryId   = p.CategoryId
                    };
                    newP.ProductDetails.Add(new Domain.Entities.ProductDetail
                    {
                        Id                = priceId,
                        ParameterValue    = psq.SizeName,
                        Quantity          = psq.Quantity,
                        PriceMinor        = priceMinor,
                        PriceReleaseMinor = priceReleaseMinor,
                        DataJson          = dataJson,
                    });
                    products.Add(newP);
                }
                else
                {
                    existing.ProductDetails.Add(new Domain.Entities.ProductDetail {
                        Id                = priceId,
                        ParameterValue    = psq.SizeName,
                        Quantity          = psq.Quantity,
                        PriceMinor        = priceMinor,
                        PriceReleaseMinor = priceReleaseMinor,
                        DataJson          = dataJson
                    });
                }
            }

            productsByCategories = new ProductsByCategoryViewModel(products);

            // Fill category names
            foreach (var c in productsByCategories.ProductsByCategories)
            {
                var firstProduct = c.Products.FirstOrDefault();
                if (firstProduct != null)
                {
                    c.CategoryName = categoryNames.Keys.Contains(firstProduct.CategoryId) ? categoryNames[firstProduct.CategoryId] : "";
                }
            }
            return(productsByCategories);
        }