// GET: /PhotoGallery/Create public ActionResult Create() { PhotoGalleryCreateViewModel vm = new PhotoGalleryCreateViewModel(); //ViewBag.photogalleries = projectService.GetProjects().Select(x => new SelectListItem { Text = x.Title, Value = x.ID.ToString() }); ViewBag.photogalleries = projectService.GetProjectsWithoutPhotoGalleries().Select(x => new SelectListItem { Text = x.Title, Value = x.ID.ToString() }); return View(vm); }
public ActionResult Create(PhotoGalleryCreateViewModel photogalleryVm, IEnumerable<HttpPostedFileBase> files) { if (ModelState.IsValid) { if (files != null) { var photogallery = new PhotoGallery(); photogallery.Project = projectService.GetProjectById(photogalleryVm.ProjectId); photoGalleryService.CreateGallery(photogallery); string galleryUploadPath= Server.MapPath(GalleryUploadFolderPath); string folderUniqueName = "Gallery" + photogallery.ID + "/"; Directory.CreateDirectory(galleryUploadPath + "\\" + folderUniqueName); string galleryPath = GalleryUploadFolderPath + folderUniqueName; foreach (var file in files) { if (file.ContentLength == 0) continue; if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); photoService.UploadPhoto(file, galleryPath, MAX_WIDTH, MAX_HEIGHT); photoService.CreatePhotoEntity(GalleryUploadFolderPath, file.FileName, folderUniqueName, photogallery); } } } return RedirectToAction("Index"); } return View(photogalleryVm); }