public ActionResult ViewAlbum(string gid) { var id = Guid.Parse(gid); var album = new Album(Dal.GetAlbumById(id)); album.Photos = Dal.GetAlbumPhotos(id).Select(x => new Photo(x)).ToList(); return(View(model: album)); }
// GET: Admin/Gallery/UploadPhotos public ActionResult UploadPhotos(string id = "") { try { int _id; AlbumInfo _albumInfo = null; if (!int.TryParse(id, out _id)) { return(RedirectToAction("Manage", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_id); } if (_albumInfo == null) { return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository Repo = new PhotoRepository()) { _albumInfo.PhotoInfoList = Repo.GetPhotoListByAlbumId(_id); } return(View(_albumInfo)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "UploadPhotos"))); } }
// GET: Admin/Gallery/UpdateAlbum public ActionResult UpdateAlbum(string id = "") { try { int _id; var _albumInfo = new AlbumInfo(); if (!int.TryParse(id, out _id)) { _albumInfo = null; return(View(_albumInfo)); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_id); } return(View(_albumInfo)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "UpdateAlbum"))); } }
private void getAlbumButton_Click(object sender, RoutedEventArgs e) { int albumId; try { albumId = Convert.ToInt32(albumIdTextBox.Text); } catch (FormatException ex) { MessageBox.Show("Geef een correct album ID in"); return; } AlbumDetails albumDetails = AlbumService.GetAlbumById(albumId); if (albumDetails.Title == null) { MessageBox.Show("Album with ID: " + albumId + " could not be found."); return; } mainGrid.DataContext = AlbumRepository.GetAlbumById(albumId); setCorrectGenre(AlbumRepository.GetAlbumById(albumId).GenreId); setCorrectArtist(AlbumRepository.GetAlbumById(albumId).ArtistId); EnableInputForms(); }
public ActionResult DeletePhoto(string PhotoId = "", string AlbumId = "") { try { int _photoId; int _albumId; PhotoInfo _photoInfo = null; AlbumInfo _albumInfo = null; if (!int.TryParse(PhotoId, out _photoId) || !int.TryParse(AlbumId, out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_albumId); } if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Album does not exist."); return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository Repo = new PhotoRepository()) { _photoInfo = Repo.GetPhotoById(_photoId); if (_photoInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Photo does not exist."); return(RedirectToAction("Manage", "Gallery")); } string fullPath = Request.MapPath(_photoInfo.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } Repo.DeletePhoto(_photoId); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Photos deleted successfully."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = AlbumId })); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeletePhoto"))); } }
// GET: Albums/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Album album = albumRepository.GetAlbumById(id); if (album == null) { return(HttpNotFound()); } ViewBag.Publishers = albumRepository.GetPublishersOfAlbum(id); ViewBag.Tracks = albumRepository.GetTracksOfAlbum(id).OrderBy(t => t.Sequnce).ToList(); return(View(album)); }
private void GetAlbumButton_Click_1(object sender, RoutedEventArgs e) { string idboxinput = AlbumIdBox.Text; int id = IntegerHandling(idboxinput); Album selectedAlbum = new Album(); selectedAlbum = AlbumRepository.GetAlbumById(id); GenreCombo.Text = GenreRepository.GetGenreById(selectedAlbum.GenreId).Name; ArtistCombo.Text = ArtistRepository.GetArtistNameById(selectedAlbum.ArtistId); TitleBox.Text = selectedAlbum.Title; PriceBox.Text = selectedAlbum.Price.ToString(); AlbumUrlBox.Text = selectedAlbum.AlbumArtUrl; }
private void GetAlbumsButton_Click(object sender, RoutedEventArgs e) { int albumId = Convert.ToInt32(AlbumIdBox.Text); Album selectedAlbum = new Album(); selectedAlbum = AlbumRepository.GetAlbumById(albumId); if (selectedAlbum.Title == null) { MessageBox.Show("there is no such album"); } else { GenreBox.Text = GenreRepository.GetGenreById(selectedAlbum.GenreId).Name; ArtistBox.Text = ArtistRepository.GetArtistNameById(selectedAlbum.ArtistId); TitleBox.Text = selectedAlbum.Title; PriceBox.Text = selectedAlbum.Price.ToString(); AlbumUrlBox.Text = selectedAlbum.AlbumArtUrl; } }
// GET: Employee/Gallery/Photos public ActionResult Photos(string id = "") { try { AlbumInfo _album = null; int _temp; if (!int.TryParse(id, out _temp)) { return(RedirectToAction("Albums", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _album = Repo.GetAlbumById(int.Parse(id)); } if (_album == null) { return(RedirectToAction("Albums", "Gallery")); } _album.PhotoInfoList = new List <PhotoInfo>(); using (PhotoRepository Repo = new PhotoRepository()) { _album.PhotoInfoList = Repo.GetPhotoListByAlbumId(int.Parse(id)); } return(View(_album)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "Albums"))); } }
public ActionResult UploadPhotos(IEnumerable <HttpPostedFileBase> files, AlbumInfo albumInfo) { try { int _albumId; int count = 0; var photoInfo = new PhotoInfo(); AlbumInfo _albumInfo = null; if (!int.TryParse(albumInfo.Id.ToString(), out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_albumId); } if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Album not found."); return(RedirectToAction("Manage", "Gallery")); } photoInfo.UploadOn = DateTime.Now; photoInfo.UploadByAccountId = CurrentUser.AccountId; photoInfo.AlbumId = albumInfo.Id; if (files != null) { foreach (var file in files) { if (file.ContentType.Contains("image")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg")) { photoInfo.Name = file.FileName; string _dirPath = Server.MapPath(Url.Content("~/Content/Album_photos")); bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath); if (!_isDirectoryExists) { System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Album_photos"))); } photoInfo.Path = Url.Content("~/Content/Album_photos/" + Guid.NewGuid() + "_" + file.FileName); string imgPath = Server.MapPath(photoInfo.Path); file.SaveAs(imgPath); using (PhotoRepository Repo = new PhotoRepository()) { Repo.SavePhoto(photoInfo); } count++; } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select jpeg, jpg format only."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select photo(s)."); return(RedirectToAction("UploadPhotos", "Admin", new { id = albumInfo.Id })); } TempData["Msg"] = AlertMessageProvider.SuccessMessage(count + " Photos uploaded successfully."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "UploadPhotos"))); } }
public ActionResult DeleteAlbum(string AlbumId = "") { try { var _photos = new List <PhotoInfo>(); int _albumId; AlbumInfo _albumInfo = null; if (!int.TryParse(AlbumId, out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (var transaction = new System.Transactions.TransactionScope()) { using (AlbumRepository AlbumRepo = new AlbumRepository()) { _albumInfo = AlbumRepo.GetAlbumById(_albumId); if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository PhotoRepo = new PhotoRepository()) { _photos = PhotoRepo.GetPhotoListByAlbumId(_albumId); foreach (var item in _photos) { string fullPath = Request.MapPath(item.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } PhotoRepo.DeletePhoto(item.Id); } } string _imgPath = Server.MapPath(_albumInfo.CoverPhotoPath); if (!_imgPath.Contains("default-album-cover.jpg")) { if (System.IO.File.Exists(_imgPath)) { System.IO.File.Delete(_imgPath); } } AlbumRepo.DeleteAlbum(_albumId); } transaction.Complete(); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Album deleted successfully."); return(RedirectToAction("Manage", "Gallery")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeleteAlbum"))); } }
public ActionResult UpdateAlbum(HttpPostedFileBase file, AlbumInfo albumInfo) { try { if (!ModelState.IsValid) { return(RedirectToAction("Manage", "Gallery")); } int _id; var _albumInfo = new AlbumInfo(); if (!int.TryParse(albumInfo.Id.ToString(), out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(View()); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_id); } if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Album does not exist."); return(RedirectToAction("Manage", "Gallery")); } albumInfo.Title = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(albumInfo.Title.ToLower()); albumInfo.ModifiedByAccountId = CurrentUser.AccountId; albumInfo.ModifiedOn = DateTime.Now; if (file != null) { if (file.ContentType.Contains("image")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg")) { if (string.IsNullOrEmpty(albumInfo.Title)) { albumInfo.Title = "Untitled Album"; } if (string.IsNullOrEmpty(albumInfo.Description)) { albumInfo.Description = ""; } if (albumInfo.CoverPhotoPath.Contains("default-album-cover.jpg")) { string _dirPath = Server.MapPath(Url.Content("~/Content/Album_coverphotos")); bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath); if (!_isDirectoryExists) { System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Album_coverphotos"))); } albumInfo.CoverPhotoPath = Url.Content("~/Content/Album_coverphotos/" + Guid.NewGuid() + "_" + file.FileName); } //else //{ // if (!System.IO.File.Exists(Server.MapPath(albumInfo.CoverPhotoPath))) // { // TempData["Msg"] = AlertMessageProvider.FailureMessage("Image does not exist."); // return View(); // } //} string imgPath = Server.MapPath(albumInfo.CoverPhotoPath); file.SaveAs(imgPath); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select jpeg, jpg format only."); return(View()); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(View()); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only."); return(View()); } } else { if (string.IsNullOrEmpty(albumInfo.Title)) { albumInfo.Title = "Untitled Album"; } if (string.IsNullOrEmpty(albumInfo.Description)) { albumInfo.Description = ""; } //albumInfo.CoverPhotoPath = Url.Content("~/Content/default-album-cover.jpg"); } using (AlbumRepository Repo = new AlbumRepository()) { Repo.UpdateAlbum(albumInfo); } return(RedirectToAction("Manage", "Gallery")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "UpdateAlbum"))); } }