コード例 #1
0
        public ActionResult Index(long id)
        {
            Composition composition = _dbCompositionService.FindById(id);

            if (composition != null)
            {
                Genre genre        = _dbGenreService.FindById(composition.GenreId);
                var   tags         = _dbTagService.FindByCompositionId(composition.Id);
                var   likeCount    = _dbLikeService.GetLikeCountByCompositionId(composition.Id);
                var   rating       = _dbRatingService.GetAverageRatingByCompositionId(composition.Id);
                var   user         = _userManager.FindByIdAsync(composition.UserId).Result;
                var   commentCount = _dbCommentService.GetCommentCountByCompositionId(composition.Id);
                return(View(new CompositionViewModel()
                {
                    Annotation = composition.Annotation,
                    GenreString = genre.GenreString,
                    ImgSource = composition.ImgSource,
                    LastPublication = composition.LastPublication,
                    Likes = likeCount,
                    Name = composition.Name,
                    Rating = rating,
                    Tags = tags,
                    UserName = user.UserName,
                    CompositionId = composition.Id,
                    UserId = user.Id,
                    Comments = commentCount
                }));
            }
            return(View());
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: C1r1ce/Cirice
        private List <CompositionViewModel> GetItems(int page)
        {
            var compositions = _dbCompositionService.GetCompositionsOrderedByDate(NumberOfLoadedCompositions, page);
            List <CompositionViewModel> list = new List <CompositionViewModel>();

            foreach (Composition composition in compositions)
            {
                Genre genre        = _dbGenreService.FindById(composition.GenreId);
                var   tags         = _dbTagService.FindByCompositionId(composition.Id);
                var   likeCount    = _dbLikeService.GetLikeCountByCompositionId(composition.Id);
                var   rating       = _dbRatingService.GetAverageRatingByCompositionId(composition.Id);
                var   user         = _userManager.FindByIdAsync(composition.UserId).Result;
                var   commentCount = _dbCommentService.GetCommentCountByCompositionId(composition.Id);
                list.Add(new CompositionViewModel()
                {
                    Annotation      = composition.Annotation,
                    GenreString     = genre.GenreString,
                    ImgSource       = composition.ImgSource,
                    LastPublication = composition.LastPublication,
                    Likes           = likeCount,
                    Name            = composition.Name,
                    Rating          = rating,
                    Tags            = tags,
                    UserName        = user.UserName,
                    CompositionId   = composition.Id,
                    UserId          = user.Id,
                    Comments        = commentCount
                });
            }

            return(list);
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: C1r1ce/Cirice
        public async Task <IActionResult> Index(string user)
        {
            var dbUser = await _userManager.FindByIdAsync(user);

            if (user != null)
            {
                var compositions = _dbCompositionService.FindByUserId(user);
                List <CompositionViewModel> list = new List <CompositionViewModel>();
                foreach (Composition composition in compositions)
                {
                    Genre genre        = _dbGenreService.FindById(composition.GenreId);
                    var   tags         = _dbTagService.FindByCompositionId(composition.Id);
                    var   likeCount    = _dbLikeService.GetLikeCountByCompositionId(composition.Id);
                    var   rating       = _dbRatingService.GetAverageRatingByCompositionId(composition.Id);
                    var   commentCount = _dbCommentService.GetCommentCountByCompositionId(composition.Id);
                    list.Add(new CompositionViewModel()
                    {
                        Annotation      = composition.Annotation,
                        GenreString     = genre.GenreString,
                        ImgSource       = composition.ImgSource,
                        LastPublication = composition.LastPublication,
                        Likes           = likeCount,
                        Name            = composition.Name,
                        Rating          = rating,
                        Tags            = tags,
                        UserName        = dbUser.UserName,
                        CompositionId   = composition.Id,
                        UserId          = dbUser.Id,
                        Comments        = commentCount
                    });
                }
                return(View(new UserViewModel()
                {
                    CompositionViewModels = list,
                    UserAbout = dbUser.About,
                    UserId = dbUser.Id,
                    UserName = dbUser.UserName
                }));
            }
            return(BadRequest());
        }