示例#1
0
        /// <summary>
        /// Get a list of all users and their ratings on every article
        /// </summary>
        public UserArticleRatingsTable GetUserArticleRatingsTable(IRater rater)
        {
            UserArticleRatingsTable table = new UserArticleRatingsTable();

            table.UserIndexToID    = db.Users.OrderBy(x => x.UserID).Select(x => x.UserID).Distinct().ToList();
            table.ArticleIndexToID = db.Articles.OrderBy(x => x.ArticleID).Select(x => x.ArticleID).Distinct().ToList();

            foreach (int userId in table.UserIndexToID)
            {
                table.Users.Add(new UserArticleRatings(userId, table.ArticleIndexToID.Count));
            }

            var userArticleRatingGroup = db.UserActions
                                         .GroupBy(x => new { x.UserID, x.ArticleID })
                                         .Select(g => new { g.Key.UserID, g.Key.ArticleID, Rating = rater.GetRating(g.ToList()) })
                                         .ToList();

            foreach (var userAction in userArticleRatingGroup)
            {
                int userIndex    = table.UserIndexToID.IndexOf(userAction.UserID);
                int articleIndex = table.ArticleIndexToID.IndexOf(userAction.ArticleID);

                table.Users[userIndex].ArticleRatings[articleIndex] = userAction.Rating;
            }

            return(table);
        }
        /// <summary>
        /// Get a list of all users and their ratings on every article
        /// </summary>
        public UserArticleRatingsTable GetUserArticleRatingsTable(IRater rater)
        {
            UserArticleRatingsTable table = new UserArticleRatingsTable();

            table.UserIndexToID    = db.Users.OrderBy(x => x.UserID).Select(x => x.UserID).Distinct().ToList();
            table.ArticleIndexToID = db.Articles.OrderBy(x => x.ArticleID).Select(x => x.ArticleID).Distinct().ToList();
            table.Ang1             = db.Articles.Select(x => x.Name).ToList();
            List <string> name = new List <string>();

            name = table.Ang1;
            foreach (int userId in table.UserIndexToID)
            {
                table.Users.Add(new UserArticleRatings(userId, table.ArticleIndexToID.Count));
            }

            List <ArticleAndTag> articleTags = new List <ArticleAndTag>();

            foreach (Article article in db.Articles)
            {
                table.art.Add(new ArticleAndTag(article.ArticleID, article.Name, article.Tags));
            }


            var userArticleRatingGroup = db.UserActions
                                         .GroupBy(x => new { x.UserID, x.ArticleID })
                                         .Select(g => new { g.Key.UserID, g.Key.ArticleID, Rating = rater.GetRating(g.ToList()) })
                                         .ToList();

            foreach (var userAction in userArticleRatingGroup)
            {
                int userIndex    = table.UserIndexToID.IndexOf(userAction.UserID);
                int articleIndex = table.ArticleIndexToID.IndexOf(userAction.ArticleID);

                table.Users[userIndex].ArticleRatings[articleIndex] = userAction.Rating;
            }

            return(table);
        }