コード例 #1
0
        // GET: ProductInCategories/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var productInCategory = await _uow.ProductsInCategories.FindAsync(id);

            if (productInCategory == null)
            {
                return(NotFound());
            }

            var viewModel = new ProductInCategoryViewModel
            {
                ProductInCategory = productInCategory,
                Categories        = new SelectList(await _uow.Categories.AllAsync(), nameof(Category.Id),
                                                   nameof(Category.CategoryAndOwnerName)),
                Products = new SelectList(await _uow.Products.AllAsync(), nameof(Product.Id),
                                          nameof(Product.ProductAndOwnerName))
            };

            return(View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("Id,CategoryId,ProductId")] ProductInCategory productInCategory)
        {
            if (id != productInCategory.Id)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                _uow.ProductsInCategories.Update(productInCategory);
                await _uow.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var viewModel = new ProductInCategoryViewModel
            {
                ProductInCategory = productInCategory,
                Categories        = new SelectList(await _uow.Categories.AllAsync(), nameof(Category.Id),
                                                   nameof(Category.CategoryAndOwnerName)),
                Products = new SelectList(await _uow.Products.AllAsync(), nameof(Product.Id),
                                          nameof(Product.ProductAndOwnerName))
            };

            return(View(viewModel));
        }
コード例 #3
0
        public ActionResult Index(int id, string url, int page = 1)
        {
            var categoryViewModel = this.categories
                .GetAll()
                .Where(x => x.Id == id)
                .To<CategoryViewModel>()
                .ToList();

            var allProducts = this.products
                .GetAll()
                .Where(x => x.CategoryId == id)
                .To<ProductDetailsViewModel>()
                .ToList();

            if (categoryViewModel == null)
            {
                return this.HttpNotFound("No such category");
            }

            var viewModel = new ProductInCategoryViewModel
            {
                Products = allProducts
            };

            return this.View(viewModel);
        }
コード例 #4
0
        // GET: ProductInCategories/Create
        public async Task <IActionResult> Create()
        {
            var viewModel = new ProductInCategoryViewModel
            {
                Categories = new SelectList(await _uow.Categories.AllAsync(), nameof(Category.Id),
                                            nameof(Category.CategoryAndOwnerName)),
                Products = new SelectList(await _uow.Products.AllAsync(), nameof(Product.Id),
                                          nameof(Product.ProductAndOwnerName))
            };

            return(View(viewModel));
        }