public ActionResult ChangeLikes(int photoId)
        {
            var user = accountService.GetUserByUserName(User.Identity.Name)?.ToMvcUser();

            photoService.ChangeNumberOfLikes(photoId, user.Id);

            var photo = photoService.GetById(photoId)?.ToMvcPhoto();

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_likes", photo));
            }

            user = accountService.GetByUserId(photo.UserId)?.ToMvcUser();
            var paging = photoService.GetCommentsPaging(photoId, commentPageSize, 1, null).ToMvcCommentsPaging();

            var photoDetail = new PhotoCommentViewModel
            {
                User          = user,
                Photo         = photo,
                CommentPaging = paging
            };

            return(View("PhotoDetails", photoDetail));
        }
        public ActionResult CreateComment(int photoId, string comment, int page)
        {
            var user = accountService.GetUserByUserName(User.Identity.Name)?.ToMvcUser();
            var comm = new CommentViewModel()
            {
                PhotoId = photoId, Description = comment, UserId = user.Id, DateOfSending = DateTime.Now
            };

            photoService.CreateComment(comm.ToBllComment());
            var paging = photoService.GetCommentsPaging(photoId, commentPageSize, page, true).ToMvcCommentsPaging();

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Comments", paging));
            }

            var photo = photoService.GetById(photoId)?.ToMvcPhoto();

            user = accountService.GetByUserId(photo.UserId)?.ToMvcUser();

            var photoDetail = new PhotoCommentViewModel
            {
                User          = user,
                Photo         = photo,
                CommentPaging = paging
            };

            return(View("PhotoDetails", photoDetail));
        }
Example #3
0
        public ActionResult CreateComment(PhotoCommentViewModel photoCommentViewModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("EmptyMessageError", "You can't post empty message");
                return(RedirectToAction("Details", new { id = photoCommentViewModel.PhotoId }));
            }
            PhotoCommentDTO photoCommentDto = Mapper.Map <PhotoCommentDTO>(photoCommentViewModel);

            _commentServices.CreateComment(photoCommentDto);
            return(RedirectToAction("Details", new { id = photoCommentViewModel.PhotoId }));
        }
Example #4
0
        public static PhotoCommentViewModel ToPhotoCommentViewModel(this PhotoCommentModel photoComment, UserModel user)
        {
            var userInfo = new UserInfoViewModel
            {
                OwnerFirstName = user.FirstName,
                OwnerLastName  = user.LastName
            };

            var photoCommentViewModel = new PhotoCommentViewModel
            {
                UserInfo       = userInfo,
                Rating         = photoComment.Rating,
                DateOfCreating = photoComment.DateOfCreating,
                Reply          = photoComment.Reply,
                Text           = photoComment.Text
            };

            return(photoCommentViewModel);
        }
        public ActionResult PhotoDetails(int photoId)
        {
            var photo = photoService.GetById(photoId)?.ToMvcPhoto();

            if (photo == null)
            {
                return(HttpNotFound());
            }

            var user   = accountService.GetByUserId(photo.UserId)?.ToMvcUser();
            var paging = photoService.GetCommentsPaging(photoId, commentPageSize, 1, null).ToMvcCommentsPaging();

            var photoDetail = new PhotoCommentViewModel
            {
                User          = user,
                Photo         = photo,
                CommentPaging = paging
            };

            return(View(photoDetail));
        }
        public ActionResult PagingComments(int photoId, int page = 1)
        {
            var paging = photoService.GetCommentsPaging(photoId, commentPageSize, page, null).ToMvcCommentsPaging();

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Comments", paging));
            }

            var photo = photoService.GetById(photoId)?.ToMvcPhoto();
            var user  = accountService.GetByUserId(photo.UserId)?.ToMvcUser();

            var photoDetail = new PhotoCommentViewModel
            {
                User          = user,
                Photo         = photo,
                CommentPaging = paging
            };

            return(View("PhotoDetails", photoDetail));
        }