public ActionResult Index() { var photo = new GalleryPhotoViewModel(); photo.MapPhoto(PhotoRepository.GetLastUploadedPhoto()); return(View(photo)); }
public static void MapPhoto(this GalleryPhotoViewModel galleryPhoto, Photo photo) { galleryPhoto.Id = photo.Id; galleryPhoto.Name = photo.Name; galleryPhoto.FileName = photo.FileName; galleryPhoto.Description = photo.Description; galleryPhoto.UploadedBy = photo.User.Name; }
public ActionResult AddComment(GalleryPhotoViewModel model) { var comment = new CommentViewModel { PhotoId = model.Id }; return(PartialView(comment)); }
public ActionResult UploadPhoto() { var photo = new GalleryPhotoViewModel(); var albums = AlbumRepository.GetAlbumsByUserId(UserRepository.GetUserId(User.Identity.Name)); albums.ForEach(x => photo.Albums.Add(new SelectListItem { Text = x.Name, Value = x.Id.ToString() })); return(PartialView(photo)); }
public ActionResult UploadPhoto(GalleryPhotoViewModel model, HttpPostedFileBase photo) { if (!ModelState.IsValid) { return(PartialView(model)); } _photoRepository.Add(model.MapPhoto(photo.FileName, UserRepository.GetUserId(User.Identity.Name))); photo.SaveAs(Path.Combine(Server.MapPath("~/Photos"), photo.FileName)); return(RedirectToAction("Index")); }
public ActionResult ViewPhotoPartial(int id) { var photo = _photoService.GetOne(id); var model = new GalleryPhotoViewModel() { Id = photo.Id, Title = CultureHelper.IsEnCulture() ? photo.TitleEng : photo.TitleRu, Path = photo.PhotoPath, Description = CultureHelper.IsEnCulture() ? photo.DescriptionEng : photo.DescriptionRu, }; return(PartialView(model)); }
public static Photo MapPhoto(this GalleryPhotoViewModel viewModel, string fileName, Guid uploader) { var photo = new Photo() { Id = Guid.NewGuid(), Name = viewModel.Name, Description = viewModel.Description, DateAdded = DateTime.Now, FileName = fileName, AlbumId = viewModel.AlbumId, UserId = uploader }; return(photo); }
public ActionResult ViewPhotoPartial(int id, bool isNext) { var photos = _photoService.GetAll().ToArray(); Photo photo = new Photo(); for (int i = 0; i < photos.Length; i++) { if (photos[i].Id == id) { if (isNext) { if (i + 1 >= photos.Length - 1) { photo = photos[0]; break; } photo = photos[i + 1]; } else { if (i - 1 < 0) { photo = photos[photos.Length - 1]; break; } photo = photos[i - 1]; } break; } } var model = new GalleryPhotoViewModel() { Id = photo.Id, Title = CultureHelper.IsEnCulture() ? photo.TitleEng : photo.TitleRu, Path = photo.PhotoPath, Description = CultureHelper.IsEnCulture() ? photo.DescriptionEng : photo.DescriptionRu, }; return(PartialView(model)); }