Пример #1
0
 public ActionResult Product(int productId)
 {
     var productRepo = new ProductRepository(Properties.Settings.Default.ConStr);
     ProductPageViewModel model = new ProductPageViewModel();
     var categoryRepo = new CategoryRepository(Properties.Settings.Default.ConStr);
     model.Catergories = categoryRepo.GetCategories();
     model.Product = productRepo.GetProductWithImages(productId);
     return View(model);
 }
Пример #2
0
        public ActionResult AddProduct(Product product, List<ImageUpload> image)
        {
            var productRepo = new ProductRepository(Properties.Settings.Default.ConStr);
            var imageRepo = new ImageRepository(Properties.Settings.Default.ConStr);

            productRepo.AddProduct(product);
            List<Image> images = new List<Image>();
            foreach (ImageUpload i in image)
            {
                var fileName = Guid.NewGuid() + Path.GetExtension(i.Image.FileName);
                i.Image.SaveAs(Server.MapPath("~/Images/") + fileName);
                images.Add(new Image
                {
                    ProductId = product.ProductId,
                    FileName = fileName,
                });
            }
            imageRepo.AddImage(images);
            return Redirect("index");
        }
Пример #3
0
        public ActionResult Index(int? categoryId, int? page)
        {
            IndexPageViewModel model = new IndexPageViewModel();
            if (categoryId == null)
            {
                categoryId = 1;
            }
            if (page == null)
            {
                page = 1;
            }

            var productRepo = new ProductRepository(Properties.Settings.Default.ConStr);
            var categoryRepo = new CategoryRepository(Properties.Settings.Default.ConStr);
            model.PageNumber = page.Value;
            model.CurrentCategory = categoryId.Value;
            model.Catergories = categoryRepo.GetCategories();
            model.Products = productRepo.GetProductsWithImage(categoryId.Value, page.Value);
            model.SetShowNextPage(productRepo.GetProductCountPerCategory(model.CurrentCategory));
            return View(model);
        }