Ejemplo n.º 1
0
        public ActionResult Create(FormCollection form, int brandId, IEnumerable<HttpPostedFileBase> fileUpload, IList<string> fileTitles, string filter)
        {
            try
            {
                using (var context = new CatalogueContainer())
                {
                    var brand = context.Brand.Include("Category").First(b => b.Id == brandId);

                    foreach (var file in fileUpload)
                    {
                        if (file != null)
                        {
                            var product = new Product { Brand = brand };
                            string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                            string filePath = Server.MapPath("~/Content/Images");
                            filePath = Path.Combine(filePath, fileName);
                            file.SaveAs(filePath);
                            product.ImageSource = fileName;

                            context.AddToProduct(product);
                        }
                    }

                    context.SaveChanges();

                    return RedirectToAction("Index", "Catalogue", new { Area = "", brand = brand.Name, category=brand.Category.Name, filter = filter });
                }
            }
            catch
            {
                return View();
            }
        }