public void CreatePhotoEntity(string galleryPath, string filename, string filepath, PhotoGallery gallery) { var photo = new Photo { Name = filename, //Path = galleryPath + foldername + "/" + filename, Path = galleryPath + filepath + filename, IsMainPhoto = false, PhotoGallery = gallery }; this.CreatePhoto(photo); }
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); }