示例#1
0
        public ActionResult GetAll()
        {
            var app      = new ServiceReference.ContractClient();
            var products = app.GetAllProducts();

            var model = new List <ProductViewModel>();

            foreach (var c in products)
            {
                var prod = new ProductViewModel
                {
                    Id          = c.Id,
                    Name        = c.Name,
                    Description = c.Description,
                    Enabled     = c.Enabled,
                    IsOffer     = c.IsOffer,
                    Percent     = c.Percent,
                    Price       = c.Price,
                    StartDay    = c.StartDay,
                    EndDay      = c.EndDay,
                    Warranty    = c.Warranty,
                    Brant       = c.Brant,
                    Stock       = c.Stock,
                    TypeStock   = c.TypeStock,
                };
                model.Add(prod);
            }
            return(View(model));
        }
示例#2
0
        public ActionResult GetById(int id = 0, bool isOffer = false)
        {
            var app        = new ServiceReference.ContractClient();
            var categories = ViewBag.LayoutModel as List <CategoryViewModel>;
            List <ProductViewModel> productsToDisplay;

            if (id == 0)
            {
                if (isOffer)
                {
                    productsToDisplay = app.GetProductLastOffers(null).Select(x => new ProductViewModel(x)).ToList();
                }
                else
                {
                    productsToDisplay = app.GetAllProducts().Select(x => new ProductViewModel(x)).ToList();
                }
            }
            else
            {
                productsToDisplay = app.GetProductByCategory(id, isOffer).Select(x => new ProductViewModel(x)).ToList();
            }


            var categoriesAmount = app.GetCategoryCount(isOffer);

            foreach (var c in categories)
            {
                c.CountProduct = categoriesAmount.FirstOrDefault(x => x.Key == c.Id).Value;
            }


            foreach (var c in productsToDisplay)
            {
                c.Images = app.GetImageByProductId(c.Id);
            }
            var model = new CategoryShowViewModel
            {
                Products   = productsToDisplay,
                Categories = categories
            };

            if (id != 0)
            {
                model.CurrentCategory = categories.FirstOrDefault(x => x.Id == id);
            }


            return(View(model));
        }