Пример #1
0
        // GET: Basket
        public ActionResult Index(string id)
        {
            List <BasketEntry> basketEntries = db.BasketEntries.Where(x => x.UserID == id).ToList();
            Dictionary <ProductViewModel, int> productList = new Dictionary <ProductViewModel, int>();

            int sum = 0;

            foreach (BasketEntry entry in basketEntries)
            {
                Product product = db.Products.FirstOrDefault(x => x.ID.ToString() == entry.ProductID);
                sum += (int)product.Price * entry.Quantity;
                ProductViewModel pvm = CustomerProductMappers.ProductToViewModel(product);
                productList.Add(pvm, entry.Quantity);
            }

            BasketViewModel basketViewModel = new BasketViewModel()
            {
                ProductsInBasket = productList,
                Sum = sum
            };

            basketViewModel.UserId = id;



            return(View(basketViewModel));
        }
Пример #2
0
        // GET: Product/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            ProductViewModel pvm = CustomerProductMappers.ProductToViewModel(product);

            return(View(pvm));
        }
Пример #3
0
        // GET: Admin/Products
        public ActionResult Index()
        {
            var products = db.Products.Include(p => p.Category).Include(p => p.Photo).OrderBy(x => x.CategoryID).ThenBy(x => x.Name);

            ProductsViewModel productsViewModel = new ProductsViewModel();

            foreach (var product in products)
            {
                ProductViewModel pvm = CustomerProductMappers.ProductToViewModel(product);
                if (product.PhotoID != null)
                {
                    pvm.Photo = CustomerProductMappers.PhotoToViewModel(product.Photo);
                }
                productsViewModel.ProductList.Add(pvm);
            }

            return(View(productsViewModel));
        }
Пример #4
0
        public ActionResult Index()
        {
            StoreContext db = new StoreContext();

            var products       = db.Products.Where(x => x.PhotoID != null).ToList();
            var newestProducts = Enumerable.Reverse(products).Take(4).ToList();

            ProductsViewModel productsViewModel = new ProductsViewModel();

            foreach (var product in newestProducts)
            {
                ProductViewModel pvm = CustomerProductMappers.ProductToViewModel(product);
                pvm.Photo = CustomerProductMappers.PhotoToViewModel(product.Photo);
                productsViewModel.ProductList.Add(pvm);
            }

            return(View(productsViewModel));
        }
Пример #5
0
        public ActionResult Filter(string id)
        {
            var products = db.Products.Where(x => x.Category.CategoryName == id);

            ProductsViewModel productsViewModel = new ProductsViewModel();

            foreach (var product in products)
            {
                ProductViewModel pvm = CustomerProductMappers.ProductToViewModel(product);
                if (product.PhotoID != null)
                {
                    pvm.Photo = CustomerProductMappers.PhotoToViewModel(product.Photo);
                }
                productsViewModel.ProductList.Add(pvm);
            }

            ViewBag.Categories = db.ProductCategories.ToList();

            return(View("Index", productsViewModel));
        }