public ActionResult Create(ProductManageViewModel productManageViewModel)
        {
            if (ModelState.IsValid)
            {
                foreach (var cli in productManageViewModel.ClientProducts)
                {
                    clientProduct = new ClientProduct
                    {
                        UsersId   = cli.UsersId,
                        ProductId = cli.ProductId
                    };
                    db.ClientProducts.Add(clientProduct);
                    db.SaveChanges();
                }

                foreach (var sup in productManageViewModel.SupportProducts)
                {
                    supportProduct = new SupportProduct
                    {
                        UsersId   = sup.UsersId,
                        ProductId = sup.ProductId
                    };
                    db.SupportProducts.Add(supportProduct);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products, "ID", "Name", productManageViewModel.ProductId);
            ViewBag.SupportId = new SelectList(db.Users.Where(s => s.UserType == "Support"), "ID", "UserName", productManageViewModel.SupportId);
            ViewBag.ClientId  = new SelectList(db.Users.Where(c => c.UserType == "Client"), "ID", "UserName", productManageViewModel.ClientId);
            return(View(productManageViewModel));
        }
예제 #2
0
        public ActionResult Create()
        {
            ProductManageViewModel viewModel = new ProductManageViewModel();

            viewModel.Product           = new Product();
            viewModel.productCategories = productCategory.Collection();
            return(View(viewModel));
        }
예제 #3
0
        public ActionResult Edit(string id)
        {
            Product product = context.Find(id);

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

            ProductManageViewModel viewModel = new ProductManageViewModel();

            viewModel.Product           = product;
            viewModel.productCategories = productCategory.Collection();
            return(View(viewModel));
        }