Example #1
0
        public ActionResult UploadNew(string name, decimal price, string shortDescription, string longDescription, int categoryid, HttpPostedFileBase[] images)
        {
            Product product = new Product();

            product.Name             = name;
            product.Price            = price;
            product.ShortDescription = shortDescription;
            product.LongDescription  = longDescription;
            product.Categoryid       = categoryid;

            ProductRepository repo = new ProductRepository(Properties.Settings.Default.Constr);

            repo.AddProduct(product);

            IEnumerable <Image> fileimages = images.Where(i
                                                          => i != null).Select(i =>
                                                                               { Guid g = Guid.NewGuid();
                                                                                 string fileName = g + ".jpg";
                                                                                 i.SaveAs(Server.MapPath("~/Uploads/" + fileName));
                                                                                 Image img = new Image {
                                                                                     FileName = fileName, ProductId = product.Id
                                                                                 };
                                                                                 return(img); });

            repo.AddImages(fileimages);

            return(RedirectToAction("ShopHomePage", "Home"));
        }