コード例 #1
0
ファイル: ProductsController.cs プロジェクト: yanpaulo/ipede
        // GET: Admin/Products/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Product product = db.Products.Find(id);
            if (product == null)
            {
                return HttpNotFound();
            }

            ProductViewModel viewModel = new ProductViewModel(product);
            ProductSessionObject sObject = new ProductSessionObject();
            string key = GenerateSessionKey();
            int defaultImageIndex = 0;

            viewModel.Images = product.Images.ToList();

            for (int i = 0; i < viewModel.Images.Count; i++)
            {
                if (viewModel.Product.MainImage == viewModel.Images[i])
                {
                    defaultImageIndex = i;
                }
            }

            sObject.Images = viewModel.Images;
            Session[key] = sObject;
            ViewBag.DefaultImageIndex = defaultImageIndex;
            ViewBag.sessionKey = key;
            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "FullName", product.CategoryId);
            return View(viewModel);
        }
コード例 #2
0
ファイル: ProductsController.cs プロジェクト: yanpaulo/ipede
 // GET: Admin/Products/Create
 public ActionResult Create()
 {
     ViewBag.CategoryID = new SelectList(db.Categories, "ID", "FullName");
     string key = GenerateSessionKey();
     Session[key] = new ProductSessionObject();
     ViewBag.sessionKey = key;
     return View();
 }