コード例 #1
0
ファイル: HomeController.cs プロジェクト: maglunde/Tankshop
        public ActionResult Category(int CategoryId)
        {
            var categories = _categoryBLL.GetAllCategoryModels().Select(c => new CategoryView()
            {
                CategoryId = c.CategoryId,
                CategoryName = c.CategoryName
            }
            ).ToList();

            var productModels = _productBLL.GetProductsByCategory(CategoryId).ToList();

            var products = new List<ProductView>();
            foreach (var product in productModels)
            {
                var imageViews = new List<ImageView>();
                foreach (var image in product.Images)
                {
                    var imageView = new ImageView()
                    {
                        ImageId = image.ImageId,
                        ProductId = image.ProductId,
                        ImageUrl = image.ImageUrl
                    };
                    imageViews.Add(imageView);
                }
                var productView = new ProductView()
                {
                    ProductId = product.ProductId,
                    ProductName = product.ProductName,
                    Description = product.Description,
                    Price = product.Price,
                    Stock = product.Stock,
                    CategoryId = product.CategoryId,
                    CategoryName = product.CategoryName,
                    Images = imageViews
                };
                products.Add(productView);
            }

            ViewBag.Categories = categories;
            ViewBag.Products = products;
            ViewBag.LoggedIn = LoginStatus();
            ViewBag.CategoryName = _categoryBLL.GetCategoryName(CategoryId) ?? "Epler?";

            return View("Index");
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: maglunde/Tankshop
        public ActionResult Index()
        {
            var categories = _categoryBLL.GetAllCategoryModels().Select(c => new CategoryView()
            {
                CategoryId = c.CategoryId,
                CategoryName = c.CategoryName
            }
            ).ToList();

            int firstCategoryWithProducts = _categoryBLL.FirstCategoryWithProducts();

            var productModels = _productBLL.GetProductsByCategory(firstCategoryWithProducts).ToList();

            var products = new List<ProductView>();
            foreach (var product in productModels)
            {
                var imageViews = new List<ImageView>();
                foreach(var image in product.Images)
                {
                    var imageView = new ImageView()
                    {
                        ImageId = image.ImageId,
                        ProductId = image.ProductId,
                        ImageUrl = image.ImageUrl
                    };
                    imageViews.Add(imageView);
                }
                var productView = new ProductView()
                {
                    ProductId = product.ProductId,
                    ProductName = product.ProductName,
                    Description = product.Description,
                    Price = product.Price,
                    Stock = product.Stock,
                    CategoryId = product.CategoryId,
                    CategoryName = product.CategoryName,
                    Images = imageViews
                };
                products.Add(productView);
            }

            ViewBag.Categories = categories ?? new List<CategoryView>();
            ViewBag.Products = products ?? new List<ProductView>();
            ViewBag.LoggedIn = LoginStatus();
            ViewBag.CategoryName = _categoryBLL.GetCategoryName(firstCategoryWithProducts);
            ViewBag.Message = TempData["Message"] != null ? TempData["Message"] : "";
            return View();
        }
コード例 #3
0
        // GET: Product
        public ActionResult Product(int ProductId, string ReturnUrl)
        {
            var product = _productBLL.GetProductModel(ProductId);
            if (product == null)
            {
                return View("~/Views/Shared/Error.cshtml");
            }

            var imageViews = new List<ImageView>();
            foreach (var image in product.Images)
            {
                var imageView = new ImageView()
                {
                    ImageId = image.ImageId,
                    ProductId = image.ProductId,
                    ImageUrl = image.ImageUrl
                };
                imageViews.Add(imageView);
            }
            var productView = new ProductView()
            {
                ProductId = product.ProductId,
                ProductName = product.ProductName,
                Description = product.Description,
                Price = product.Price,
                Stock = product.Stock,
                CategoryId = product.CategoryId,
                CategoryName = product.CategoryName,
                Images = imageViews
            };

            ViewBag.Product = productView;
            ViewBag.ReturnUrl = ReturnUrl;
            ViewBag.LoggedIn = LoginStatus();
            return View();
        }
コード例 #4
0
        public ActionResult Index()
        {
            var productModels = _productBLL.GetAllProductModels();

            var products = new List<ProductView>();
            foreach (var product in productModels)
            {
                var imageViews = new List<ImageView>();
                foreach (var image in product.Images)
                {
                    var imageView = new ImageView()
                    {
                        ImageId = image.ImageId,
                        ProductId = image.ProductId,
                        ImageUrl = image.ImageUrl
                    };
                    imageViews.Add(imageView);
                }
                var productView = new ProductView()
                {
                    ProductId = product.ProductId,
                    ProductName = product.ProductName,
                    Description = product.Description,
                    Price = product.Price,
                    Stock = product.Stock,
                    CategoryName = product.CategoryName,
                    Images = imageViews
                };
                products.Add(productView);
            }

            ViewBag.Products = products;

            return View("ListProduct");
        }
コード例 #5
0
        public ActionResult EditProduct(string ProductId)
        {
            List<SelectListItem> categoryIds = new List<SelectListItem>();
            var allCategories = _categoryBLL.GetAllCategoryModels();

            foreach (var c in allCategories)
            {
                string categoryId = Convert.ToString(c.CategoryId);
                categoryIds.Add(new SelectListItem { Text = c.CategoryName, Value = categoryId });
            }

            ViewBag.CategoryIds = categoryIds;

            int nProductId;

            try
            {
                nProductId = Convert.ToInt32(ProductId);
            }
            catch (Exception e)
            {
                LogHandler.WriteToLog(e);
                ViewBag.Title = "Error";
                ViewBag.Message = "Invalid prodct id: " + ProductId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var product = _productBLL.GetProductModel(nProductId);

            if (product == null)
            {
                ViewBag.Title = "Error";
                ViewBag.Message = "Could not find a product with the id: " + ProductId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var imageViews = new List<ImageView>();
            foreach (var image in product.Images)
            {
                var imageView = new ImageView()
                {
                    ImageId = image.ImageId,
                    ProductId = image.ProductId,
                    ImageUrl = image.ImageUrl
                };
                imageViews.Add(imageView);
            }
            var productView = new ProductView()
            {
                ProductId = product.ProductId,
                ProductName = product.ProductName,
                Description = product.Description,
                Price = product.Price,
                Stock = product.Stock,
                CategoryId = product.CategoryId,
                CategoryName = product.CategoryName,
                Images = imageViews
            };

            ViewBag.Product = productView;

            return View();
        }
コード例 #6
0
        public ActionResult DeleteProduct(string ProductId)
        {
            int nProductId;

            try
            {
                nProductId = Convert.ToInt32(ProductId);
            }
            catch (Exception e)
            {
                LogHandler.WriteToLog(e);
                ViewBag.Title = "Error";
                ViewBag.Message = "Invalid prodct id: " + ProductId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var product = _productBLL.GetProductModel(nProductId);

            if (product == null)
            {
                ViewBag.Title = "Error";
                ViewBag.Message = "Could not find a product with the id: " + ProductId;
                return View("~/Views/Shared/Result.cshtml");
            }

            var imageViews = new List<ImageView>();
            foreach (var image in product.Images)
            {
                var imageView = new ImageView()
                {
                    ImageId = image.ImageId,
                    ProductId = image.ProductId,
                    ImageUrl = image.ImageUrl
                };
                imageViews.Add(imageView);
            }
            var productView = new ProductView()
            {
                ProductId = product.ProductId,
                ProductName = product.ProductName,
                Description = product.Description,
                Price = product.Price,
                Stock = product.Stock,
                CategoryName = product.CategoryName,
                Images = imageViews
            };
            ViewBag.Product = productView;

            return View();
        }