Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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 }));
        }
Ejemplo n.º 3
0
 public async Task <PhotoViewModel> Get(int id)
 {
     return(PhotosMapper.Map(await _photosService.GetAsync(id)));
 }
Ejemplo n.º 4
0
        /// <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);
        }