Ejemplo n.º 1
0
        public ActionResult Create()
        {
            ViewBag.Filters = FiltersMapper.MapRange(_photosService.Filters);
            //ViewBag.Tags = _tagsMapper.MapRange(_photosService.Tags);

            return(View(UsersMapper.Map(_currentUserService.GetDTO)));
        }
Ejemplo n.º 2
0
        public ActionResult Details(string userName)
        {
            UserViewModel item = UsersDetailsMapper.Map(_usersService.Get(userName));

            if (User.Identity.IsAuthenticated)
            {
                ViewBag.CurrentUser = UsersMapper.Map(_currentUserService.GetDTO);
            }

            return(View(item));
        }
Ejemplo n.º 3
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.º 4
0
        public ActionResult Details(string name)
        {
            TagViewModel item = TagsMapper.Map(_tagsService.Get(name));

            if (User.Identity.IsAuthenticated)
            {
                ViewBag.CurrentUser = UsersMapper.Map(_currentUserService.GetDTO);
            }

            return(View(item));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Helps map user entity to user data transfer object.
        /// </summary>
        protected UserDTO MapUser(User user)
        {
            User currentUser = _currentUserService.Get;

            return(UsersMapper.Map(
                       user,
                       _unitOfWork.Confirmations.Find(c => c.UserId == user.Id).FirstOrDefault() != null,
                       _unitOfWork.Followings.Find(f => f.FollowedUserId == user.Id && f.UserId == currentUser.Id).FirstOrDefault() != null,
                       _unitOfWork.Blockings.Find(b => b.BlockedUserId == user.Id && b.UserId == currentUser.Id).FirstOrDefault() != null,
                       _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == user.Id).FirstOrDefault() != null
                       ));
        }
Ejemplo n.º 6
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.º 7
0
        public async Task <ActionResult> Delete(int id)
        {
            PhotoDTO item = await _photosService.GetAsync(id);

            UserViewModel user = UsersMapper.Map(_usersService.Get(item.Owner.UserName));

            if (item != null && (user.UserName == item.Owner.UserName || User.IsInRole("Admin")))
            {
                var filePath = Path.Combine(_environment.WebRootPath, "data/photos") + $@"/{user.UserName}/{item.Path}";

                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }

                await _photosService.DeleteAsync(id);
            }

            return(RedirectToAction("Details", "Users", new { userName = user.UserName }));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Helps map user details entity to user details data transfer object.
        /// </summary>
        protected UserDetailsDTO MapUserDetails(User user)
        {
            User currentUser = _currentUserService.Get;

            var followings = new List <UserDTO>();
            var followers  = new List <UserDTO>();

            if (currentUser == null)
            {
                foreach (var following in _unitOfWork.Followings.Find(f => f.UserId == user.Id))
                {
                    followings.Add(UsersMapper.Map(
                                       following.FollowedUser,
                                       _unitOfWork.Confirmations.Find(c => c.UserId == following.FollowedUserId).FirstOrDefault() != null,
                                       false, false, false
                                       ));
                }

                foreach (var follower in _unitOfWork.Followings.Find(f => f.FollowedUserId == user.Id))
                {
                    followers.Add(UsersMapper.Map(
                                      follower.User,
                                      _unitOfWork.Confirmations.Find(c => c.UserId == follower.UserId).FirstOrDefault() != null,
                                      false, false, false
                                      ));
                }

                return(UsersDetailsMapper.Map(
                           user,
                           _unitOfWork.Confirmations.Find(c => c.UserId == user.Id).FirstOrDefault() != null,
                           false,
                           false,
                           false,
                           followings,
                           followers,
                           null
                           ));
            }
            else
            {
                foreach (var following in _unitOfWork.Followings.Find(f => f.UserId == user.Id))
                {
                    followings.Add(UsersMapper.Map(
                                       following.FollowedUser,
                                       _unitOfWork.Confirmations.Find(c => c.UserId == following.FollowedUserId).FirstOrDefault() != null,
                                       _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == user.Id).FirstOrDefault() != null,
                                       _unitOfWork.Followings.Find(f => f.FollowedUserId == following.FollowedUserId && f.UserId == currentUser.Id).FirstOrDefault() != null,
                                       _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == user.Id).FirstOrDefault() != null
                                       ));
                }

                foreach (var follower in _unitOfWork.Followings.Find(f => f.FollowedUserId == user.Id))
                {
                    followers.Add(UsersMapper.Map(
                                      follower.User,
                                      _unitOfWork.Confirmations.Find(c => c.UserId == follower.UserId).FirstOrDefault() != null,
                                      _unitOfWork.Followings.Find(f => f.FollowedUserId == follower.UserId && f.UserId == currentUser.Id).FirstOrDefault() != null,
                                      _unitOfWork.Blockings.Find(b => b.BlockedUserId == follower.UserId && b.UserId == currentUser.Id).FirstOrDefault() != null,
                                      _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == user.Id).FirstOrDefault() != null
                                      ));
                }

                var mutuals = new List <UserDTO>();

                if (followers.Count > 0)
                {
                    foreach (var follower in _unitOfWork.Followings.Find(f => f.FollowedUserId == currentUser.Id))
                    {
                        if (follower.UserId != user.Id && _unitOfWork.Followings.Find(f => f.FollowedUserId == user.Id && f.UserId == follower.UserId).FirstOrDefault() != null)
                        {
                            mutuals.Add(UsersMapper.Map(
                                            follower.User,
                                            _unitOfWork.Confirmations.Find(c => c.UserId == follower.UserId).FirstOrDefault() != null,
                                            _unitOfWork.Followings.Find(f => f.FollowedUserId == follower.UserId && f.UserId == currentUser.Id).FirstOrDefault() != null,
                                            _unitOfWork.Blockings.Find(b => b.BlockedUserId == follower.UserId && b.UserId == currentUser.Id).FirstOrDefault() != null,
                                            _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == user.Id).FirstOrDefault() != null
                                            ));
                        }
                    }
                }

                return(UsersDetailsMapper.Map(
                           user,
                           _unitOfWork.Confirmations.Find(c => c.UserId == user.Id).FirstOrDefault() != null,
                           _unitOfWork.Followings.Find(f => f.FollowedUserId == user.Id && f.UserId == currentUser.Id).FirstOrDefault() != null,
                           _unitOfWork.Blockings.Find(b => b.BlockedUserId == user.Id && b.UserId == currentUser.Id).FirstOrDefault() != null,
                           _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == user.Id).FirstOrDefault() != null,
                           followings,
                           followers,
                           mutuals
                           ));
            }
        }
Ejemplo n.º 9
0
 public AutoMapperProfile()
 {
     UsersMapper.Map(this);
 }
Ejemplo n.º 10
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);
        }