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()); }
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); }
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()); }