Ejemplo n.º 1
0
 //
 // GET: /Products/Create
 public ActionResult Create()
 {
     var viewModel = new NewProductViewModel();
     viewModel.ProductTypes = db.ProductTypes.Select(x => new SelectListItem { Value = x.Name, Text = x.Name }).ToList();
     viewModel.SelectedTypeId = "Good";
     return View(viewModel);
 }
Ejemplo n.º 2
0
        public ActionResult Create(NewProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                foreach (string file in Request.Files)
                {
                    HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                    if (hpf.ContentLength > 0) productViewModel.Product.ImageURI = blobs.Upload(hpf);
                    // TODO: stop the loop once one image has been added
                }
                productViewModel.Product.ProductTypeId = db.ProductTypes.Where(pt => pt.Name == productViewModel.SelectedTypeId).FirstOrDefault().ProductTypeId;
                db.Products.Add(productViewModel.Product);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(productViewModel);
        }