Пример #1
0
 public ActionResult AddImage(IEnumerable<HttpPostedFileBase> fileUpload)
 {
     using (var context = new CatalogueContainer())
     {
         foreach (var file in fileUpload)
         {
             if (file != null)
             {
                 string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                 string filePath = Server.MapPath("~/Content/Images");
                 filePath = Path.Combine(filePath, fileName);
                 file.SaveAs(filePath);
                 var mpi = new MainPageImage() {ImageSource = fileName};
                 context.AddToMainPageImage(mpi);
                 context.SaveChanges();
             }
         }
         return RedirectToAction("Index", "Home", new {area = ""});
     }
 }