예제 #1
0
        public ActionResult RecommendUsers(string userName)
        {
            User user;

            using (RecommenderContext db = new RecommenderContext())
            {
                user = db.Users.Where(u => u.Name == userName).FirstOrDefault();
            }

            Slope slope            = new Slope();
            var   recommendedUsers = slope.GetRecommendations(user);

            foreach (var u in recommendedUsers)
            {
                using (RecommenderContext db = new RecommenderContext())
                {
                    db.UserToUser.Add(new UserToUser()
                    {
                        User1 = user,
                        User2 = u.Key
                    });
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index", new { userName = userName }));
        }