public ActionResult Create(CreatePhotoViewModel model) { if (model.PhotoUpload == null || model.PhotoUpload.ContentLength == 0) { ModelState.AddModelError("PhotoUpload", "This field is required"); } if (model.PhotoUpload.ContentLength >= 5000000) { ModelState.AddModelError("PhotoUpload", "Photo is too big! Please resize to under 5mb or contact Alex"); } if (ModelState.IsValid) { PhotoUploader photoUploader = new PhotoUploader(); var photo = new Photo { Title = model.Title, Description = model.Description, GalleryId = model.GalleryId, FileName = model.PhotoUpload.FileName, Width = Image.FromStream(model.PhotoUpload.InputStream, false, false).Width, Height = Image.FromStream(model.PhotoUpload.InputStream, false, false).Height }; if (model.PhotoUpload != null && model.PhotoUpload.ContentLength > 0) { photo = photoUploader.SavePhotoToFileSystem(photo, model.PhotoUpload); repository.Add(photo); repository.Save(); } return RedirectToAction("ViewGallery", "Gallery", new {id = model.GalleryId}); } return View(model); }
public ActionResult Create(CreateGalleryViewModel galleryViewModel) { if (ModelState.IsValid) { GalleryService galleryService = new GalleryService(); PhotoUploader photoUploader = new PhotoUploader(); Gallery gallery = galleryService.CreateGallery(galleryViewModel.GalleryName, galleryViewModel.Description); repository.Add(gallery); repository.Save(); gallery.Path = Server.MapPath("/Photos/" + gallery.Id); galleryService.CreateDirectoryStructure(gallery.Path); List<Photo> photos = photoUploader.UploadMultiplePhotos(galleryViewModel.PhotoUpload, gallery.Id); repository.AddPhotos(photos); repository.Save(); return RedirectToAction("ViewGallery", "Gallery", new {id = gallery.Id}); } return View(new CreateGalleryViewModel()); }