public virtual ActionResult Create(int? page, FormCollection form) { try { PhotoAlbum albumToAdd = new PhotoAlbum(); TryUpdateModel<PhotoAlbum>(albumToAdd, form.ToValueProvider()); albumToAdd.AlbumFileLocation=(Path.Combine(ConfigurationManager.AppSettings["PhotoPath"],albumToAdd.Name)); albumToAdd.Description=String.IsNullOrEmpty(albumToAdd.Description) ? "" : albumToAdd.Description; albumToAdd.AlbumCoverUrl = UploadAlbumCover(albumToAdd.Name); albumToAdd.IsActive = true; db.AddToPhotoAlbums(albumToAdd); db.SaveChanges(true); CreateAlbumDirectory(albumToAdd.Name); return RedirectToAction("Index", new{@page=page}); } catch { return RedirectToAction("Index"); } }
public virtual ActionResult Albums(string ID, string refID) { PhotoAlbum album = new PhotoAlbum(); album.Name = ID; if (String.IsNullOrEmpty(ID)) { Response.Redirect("~/Photos.aspx"); } else { string photoPath = Server.MapPath("~/images/photos/"); DirectoryInfo di = new DirectoryInfo(photoPath + ID + "\\"); FileInfo[] files = di.GetFiles("*.jpg"); foreach (FileInfo fi in files) { try { album.Photos.Add(new Photo() { Name = fi.Name, }); } catch { throw; } } return View(album); } return View(new PhotoAlbum() { Name = "", Description = "", AlbumCoverUrl = "" }); }
private bool DeleteMoveAlbum(PhotoAlbum albumToDelete) { String oldAlbumPath = Server.MapPath(albumToDelete.AlbumFileLocation); string deletedAlbumPath = Server.MapPath(Path.Combine(ConfigurationManager.AppSettings["DeletedAlbumPath"].ToString() , albumToDelete.Name)); //if the album is already there (and there are files), timestamp the old one and move the new one in. if (Directory.Exists(deletedAlbumPath)) { if (Directory.GetFiles(deletedAlbumPath).Count<string>() > 0) { //string of timestamped deleted directory string newDeleteAlbumPath = (Path.Combine(deletedAlbumPath, DateTime.Today.ToShortDateString().Replace("/", "_"))); //create timestamped directory if it doesn't exist. if (!Directory.Exists(newDeleteAlbumPath)) { Directory.CreateDirectory(newDeleteAlbumPath); } //move files that are in deleted folder to new timestamped folder foreach (string fi in Directory.GetFiles(deletedAlbumPath)) { if (!System.IO.File.Exists(Path.Combine(newDeleteAlbumPath, fi))) new FileInfo(Path.Combine(deletedAlbumPath, fi)).MoveTo(newDeleteAlbumPath); } //move old files to timestamepd deleted folder. foreach (string fi in Directory.GetFiles(oldAlbumPath)) { new FileInfo(Path.Combine(deletedAlbumPath, fi)).MoveTo(newDeleteAlbumPath); } //delete old directory Directory.Delete(oldAlbumPath); } else { foreach (string fi in Directory.GetFiles(oldAlbumPath)) { new FileInfo(Path.Combine(deletedAlbumPath, fi)).MoveTo(deletedAlbumPath); } //delete old directory Directory.Delete(oldAlbumPath); } } else { Directory.Move(oldAlbumPath, deletedAlbumPath); } return true; }