public async Task <IActionResult> Index() { try { var model = new IndexReviewViewModel(); var userId = this.wrapper.GetLoggedUserId(User); var user = await this.userService.GetUserByIdAsync(userId); var businessUnit = new BusinessUnitDTO(); if (user.BusinessUnitId.HasValue) { businessUnit = await this.businessUnitService.GetBusinessUnitById(user.BusinessUnitId.Value); } else { return(BadRequest(string.Format(WebConstants.BusinessUniNotAssigned))); } var reviews = await this.reviewService.GetAllReviewsByModeratorIdAsync(userId); model.Reviews = reviews.Select(x => x.MapFrom()).ToList(); model.BusinessUnit = businessUnit.MapFrom(); model.ModeratorId = userId; return(View(model)); } catch (Exception ex) { log.Error("Unexpected exception occured:", ex); return(RedirectToAction("Error", "Home")); } }
public async Task <ActionResult> Index() { var query = from r in Db.Reviews join u in Db.Users on r.AuthorId equals u.Id into lj from u in lj.DefaultIfEmpty() join s in Db.Subjects on r.SubjectId equals s.SubjectId orderby r.DateCreate descending select new CustomReviewDTO { ReviewId = r.ReviewId, Content = r.Content, Dislike = r.Dislike, Exp = r.Exp, Like = r.Like, Rating = r.Rating, Image = r.Image, Recommend = r.Recommend, Username = u.UserName, Subjectname = s.Name }; var reviews = await query.ToListAsync(); var content = new IndexReviewViewModel { Reviews = reviews }; return(View(content)); }