public virtual ActionResult Detail(string categorySlug, string photoSlug) { var photo = _context.FindPhotoBySlug(photoSlug); if (photo == null || !string.Equals(photo.Category.Slug, categorySlug, StringComparison.CurrentCulture)) { return(HttpNotFound()); } if (!photo.IsApproved && (HttpContext.FindUser().UserId != photo.UserId || HttpContext.FindUser().IsAdmin)) { return(HttpNotFound()); } _context.CreateUserPhotoAction(HttpContext.FindUser(false)?.UserId, photo.PhotoId, UserPhotoActionType.View, false); var model = new PhotoDetailViewModel { Photo = photo, PhotosCount = _context.FindPhotoCountsByUserId(photo.User.UserId), ViewsCount = _context.FindUserPhotoActionsCountByType(photo.PhotoId, UserPhotoActionType.View), LikesCount = _context.FindUserPhotoActionsCountByType(photo.PhotoId, UserPhotoActionType.Like), CommentsCount = _context.FindCommentsCountByPhotoId(photo.PhotoId), DownloadsCount = _context.FindUserPhotoActionsCountByType(photo.PhotoId, UserPhotoActionType.Download), IsLiked = Request.IsAuthenticated && _context.HasUserPhotoAction(HttpContext.FindUser().UserId, photo.PhotoId, UserPhotoActionType.Like), LikedUsers = _context.FindUserPhotoActionsByType(photo.PhotoId, UserPhotoActionType.Like), Comments = _context.FindCommentsByPhotoId(photo.PhotoId, 1, int.MaxValue) }; return(View(Views.Detail, model)); }