public IList <PlaceReviewListItemModel> GetList(PlaceReviewListFilterModel filter) { var reviews = placeReviewRepository.CreateQuery().Where(x => x.Review.PlaceId == filter.PlaceId).ToList(); var result = reviews.Select(x => new PlaceReviewListItemModel { Id = x.Id, GId = x.Review.Place.GId, Review = x.Review.Text, Rating = x.Review.Rating, ReviewedBy = x.Review.User.UserName, ImageUri = imageService.GetImagePath(x.Review.ImageId), PlaceName = x.Review.Place.Name }); return(result.ToList()); }
public IList <GroupedPlaceReviewListItemModel> GetGroupedList(PlaceReviewListFilterModel filter) { var reviews = (from pr in placeReviewRepository.CreateQuery() group pr by new { pr.Review.PlaceId }).ToList(); var result = reviews.Select(x => new GroupedPlaceReviewListItemModel { PlaceId = x.FirstOrDefault().Review.PlaceId, PlaceName = x.FirstOrDefault().Review.Place.Name, GId = x.FirstOrDefault().Review.Place.GId, RatingAverage = x.Average(y => y.Review.Rating), ReviewCount = x.Count(), ImageUri = imageService.GetImagePath(x.FirstOrDefault().Review.ImageId), PlaceTypeIds = x.FirstOrDefault().Review.Place.PlacePlaceType.Select(y => y.PlaceTypeId).ToArray(), Lat = Convert.ToDouble(x.FirstOrDefault().Review.Place.Lat), Lng = Convert.ToDouble(x.FirstOrDefault().Review.Place.Lng), }).OrderByDescending(x => x.RatingAverage).ToList(); return(result); }
public IHttpActionResult GetGroupedList(PlaceReviewListFilterModel filter) { var model = placeReviewService.GetGroupedList(filter); return(Ok(model)); }