public ActionResult Update(long photoId) { //Getting photo by photo Id and storing in a presentation object. PhotosPO mappedPhoto = PhotosMapper.MapDoToPO(dataAccess.ViewPhotoByPhotoId(photoId)); //Puts Album name and Id into viewbag as a list to use for a dropdown list in view. ViewBag.DropDown = new List <SelectListItem>(); List <AlbumDO> dataObjects = albumData.ReadAlbum(); try { foreach (AlbumDO item in dataObjects) { //Filling a SelectListItem with with all AlbumName and AlbumId properties. ViewBag.DropDown.Add(new SelectListItem() { Text = item.AlbumName, Value = item.AlbumId.ToString() }); } } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "Update", ex.StackTrace); } return(View(mappedPhoto)); }
public ActionResult Update(PhotosPO photos) { //Defaults redirect to index of photos controller passing albumId. ActionResult oResult = RedirectToAction("Index", "Photos", new { albumId = photos.AlbumId }); if (ModelState.IsValid) { try { //Passing photo object and photo location to use in stored procedure. dataAccess.UpdatePhoto(PhotosMapper.MapPoToDO(photos, photos.PhotoLocation)); TempData["Message"] = "Photo successfully updated."; } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "Update", ex.StackTrace); oResult = View(new { albumId = photos.AlbumId }); } } else { //returns the albumId to the view. oResult = View(new { albumId = photos.AlbumId }); } return(oResult); }
public async Task <ActionResult> Details(int id) { PhotoViewModel item = PhotosMapper.Map(await _photosService.GetAsync(id)); if (User.Identity.IsAuthenticated) { ViewBag.CurrentUser = UsersMapper.Map(_currentUserService.GetDTO); } return(View(item)); }
public ActionResult Portfolio() { List<PhotosPO> mappedPhotos = new List<PhotosPO>(); ActionResult oResult = RedirectToAction("Index", "Home"); try { mappedPhotos = PhotosMapper.MapDoToPO(dataAccess.ViewPhotosById(4)); oResult = View(mappedPhotos); } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "HomeController", "Portfolio", ex.StackTrace); } return oResult; }
public async Task <ActionResult> Edit(int id) { PhotoDTO item = await _photosService.GetAsync(id); UserViewModel user = UsersMapper.Map(_usersService.Get(item.Owner.UserName)); if (item != null && user != null && (user.UserName == item.Owner.UserName || User.IsInRole("Admin"))) { ViewBag.LikesCount = item.Likes.Count(); ViewBag.Filters = FiltersMapper.MapRange(_photosService.Filters); //ViewBag.Tags = _tagsMapper.MapRange(_photosService.Tags); return(View(PhotosMapper.Map(item))); } return(RedirectToAction("Details", "Photos", new { id = item.Id })); }
public ActionResult Index(long albumId) { //Instanciating a list of photo objects to fill. List <PhotosPO> mappedItems = new List <PhotosPO>(); try { //Display photos that belong to user and provide actions to authenticated users. List <PhotosDO> dataObjects = dataAccess.ViewPhotosById(albumId); mappedItems = PhotosMapper.MapDoToPO(dataObjects); } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "Index", ex.StackTrace); TempData["Error"] = ex.Message; } return(View(mappedItems)); }
public ActionResult UploadPhoto(HttpPostedFileBase uploadedPhoto, PhotosPO photo) { //Defaults redirect to index of album controller. ActionResult oResult = RedirectToAction("Index", "Album"); if (ModelState.IsValid) { try { //Gets filepath List <FileInfo> files = Directory.GetFiles("/").Select(path => new FileInfo(path)).ToList(); //Creates a unique id for naming save files to prevent overriding, saves file in //userPhotos folder of current directory. string newName = Guid.NewGuid().ToString() + uploadedPhoto.FileName.Remove(0, uploadedPhoto.FileName.IndexOf('.')); string pathToSaveTo = Path.Combine(Server.MapPath("/userPhotos/"), newName); //Uploads photo to userPhotos folder in current directory. uploadedPhoto.SaveAs(pathToSaveTo); pathToSaveTo = $"~/userPhotos/{newName}"; //Adds photo to table using a stored procedure and properties gathered from user input. dataAccess.CreatePhoto(PhotosMapper.MapPoToDO(photo, pathToSaveTo)); //Lets user know that upload was successful. TempData["Message"] = "Photo upload successful."; } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "UploadPhoto", ex.StackTrace); TempData["Error"] = "Oops there was a problem uploading your photo, please try again."; } } else { //Instanciating a new list of selectlistitem to fill dropdown. ViewBag.DropDown = new List <SelectListItem>(); try { //Stores Album name and Id in viewbag as a list to use for a dropdown list in view. List <AlbumDO> dataObjects = albumData.ReadAlbum(); foreach (AlbumDO item in dataObjects) { ViewBag.DropDown.Add(new SelectListItem() { Text = item.AlbumName, Value = item.AlbumId.ToString() }); } } catch (Exception e) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", e.Message, "PhotosController", "UploadPhoto", e.StackTrace); } //Modelstate wasn't valid, returning photo to view. oResult = View(photo); } return(oResult); }
public IEnumerable <PhotoViewModel> Search(int page, string search, int?iso, double?exposure, double?aperture, double?focalLength) { return(PhotosMapper.MapRange(_photosService.Search(page, search, _getHomePageSize, iso, exposure, aperture, focalLength))); }
public IEnumerable <PhotoViewModel> GetTags(int tagId, int page) { return(PhotosMapper.MapRange(_photosService.GetTags(tagId, page, _getAllPageSize))); }
public IEnumerable <PhotoViewModel> GetBookmarks(int page) { return(PhotosMapper.MapRange(_photosService.GetBookmarks(page, _getAllPageSize))); }
public IEnumerable <PhotoViewModel> GetForTag(string tagName) { return(PhotosMapper.MapRange(_photosService.GetForTag(tagName, _getForTagPageSize))); }
public IEnumerable <PhotoViewModel> GetForUser(int page, string userName) { return(PhotosMapper.MapRange(_photosService.GetForUser(page, userName, _getForUserPageSize))); }
public IEnumerable <PhotoViewModel> GetPhotosHome(int page) { return(PhotosMapper.MapRange(_photosService.GetPhotosHome(page, _getHomePageSize))); }
public async Task <PhotoViewModel> Get(int id) { return(PhotosMapper.Map(await _photosService.GetAsync(id))); }
/// <summary> /// Helps map photo data transfer object. /// </summary> protected PhotoDTO MapPhoto(Photo photo) { User currentUser = _currentUserService.Get; if (currentUser == null) { var likes = new List <LikeDTO>(photo.Likes.Count); foreach (var like in photo.Likes) { likes.Add(LikesMapper.Map(like, UsersMapper.Map( like.Owner, _unitOfWork.Confirmations.Find(c => c.UserId == like.OwnerId).FirstOrDefault() != null, false, false, false ))); } var comments = new List <CommentDTO>(photo.Comments.Count); foreach (var comment in photo.Comments) { comments.Add(CommentsMapper.Map( comment, UsersMapper.Map( comment.Owner, _unitOfWork.Confirmations.Find(c => c.UserId == comment.OwnerId).FirstOrDefault() != null, false, false, false ))); } return(PhotosMapper.Map( photo, false, false, UsersMapper.Map( photo.Owner, _unitOfWork.Confirmations.Find(c => c.UserId == photo.OwnerId).FirstOrDefault() != null, false, false, false ), likes, comments, TagsMapper.MapRange(_unitOfWork.Tagings.Find(t => t.PhotoId == photo.Id).Select(t => t.Tag)))); } if (_unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == photo.OwnerId).FirstOrDefault() == null) { var likes = new List <LikeDTO>(photo.Likes.Count); foreach (var like in photo.Likes) { likes.Add(LikesMapper.Map(like, UsersMapper.Map( like.Owner, _unitOfWork.Confirmations.Find(c => c.UserId == like.OwnerId).FirstOrDefault() != null, _unitOfWork.Followings.Find(f => f.FollowedUserId == like.OwnerId && f.UserId == currentUser.Id).FirstOrDefault() != null, _unitOfWork.Blockings.Find(b => b.BlockedUserId == like.OwnerId && b.UserId == currentUser.Id).FirstOrDefault() != null, _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == currentUser.Id).FirstOrDefault() != null ))); } var comments = new List <CommentDTO>(photo.Comments.Count); foreach (var comment in photo.Comments) { comments.Add(CommentsMapper.Map( comment, UsersMapper.Map( comment.Owner, _unitOfWork.Confirmations.Find(c => c.UserId == comment.OwnerId).FirstOrDefault() != null, _unitOfWork.Followings.Find(f => f.FollowedUserId == comment.OwnerId && f.UserId == currentUser.Id).FirstOrDefault() != null, _unitOfWork.Blockings.Find(b => b.BlockedUserId == comment.OwnerId && b.UserId == currentUser.Id).FirstOrDefault() != null, _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == currentUser.Id).FirstOrDefault() != null ))); } return(PhotosMapper.Map( photo, _unitOfWork.Likes.Find(l => l.OwnerId == currentUser.Id && l.PhotoId == photo.Id).FirstOrDefault() != null, _unitOfWork.Bookmarks.Find(b => b.UserId == currentUser.Id && b.PhotoId == photo.Id).FirstOrDefault() != null, UsersMapper.Map( photo.Owner, _unitOfWork.Confirmations.Find(c => c.UserId == photo.OwnerId).FirstOrDefault() != null, _unitOfWork.Followings.Find(f => f.FollowedUserId == photo.OwnerId && f.UserId == currentUser.Id).FirstOrDefault() != null, _unitOfWork.Blockings.Find(b => b.BlockedUserId == photo.OwnerId && b.UserId == currentUser.Id).FirstOrDefault() != null, _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == photo.OwnerId).FirstOrDefault() != null ), likes, comments, TagsMapper.MapRange(_unitOfWork.Tagings.Find(t => t.PhotoId == photo.Id).Select(t => t.Tag)))); } return(null); }