Esempio n. 1
0
        public ActionResult Create(GalleryImage model)
        {
            try
            {
                
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var siteImage = new GalleryImage();
                    var file = Request.Files[i];
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    siteImage.ImageSource = fileName;
                    _repository.AddGalleryImage(siteImage);
                }
                
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.Message + (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message) ? ex.InnerException.Message : "");
                return View(model);
            }

            return RedirectToAction("Index");
        }
Esempio n. 2
0
 public int AddGalleryImage(GalleryImage galleryImage)
 {
     _store.GalleryImages.Add(galleryImage);
     _store.SaveChanges();
     return galleryImage.Id;
 }