Ejemplo n.º 1
0
        public void UpdateRatingForAllPublications()
        {
            var publications = Publications
                               .Include(pub => pub.Reviews)
                               .Where(p => p.Reviews.Count != 0);

            foreach (var publication in publications)
            {
                publication.Rating = publication.Reviews.Average(rev => rev.Rating);
            }
            Publications.UpdateRange(publications);
        }
Ejemplo n.º 2
0
        public void UpdateRatingForPublication(int publicationId)
        {
            var publication = Publications.Include(pub => pub.Reviews).Where(p => p.Id == publicationId).FirstOrDefault();

            if (publication.Reviews.Count > 0)
            {
                publication.Rating = publication.Reviews.Average(rev => rev.Rating);
            }
            else
            {
                publication.Rating = 0;
            }
            Publications.Update(publication);
        }