Пример #1
0
        public ActionResult Index(string uid)
        {
            var UsersList = Context.Users.FindAll();
            var User      = Context.Users.FindOneById(new ObjectId(uid));

            // sum the prefrences of user
            double sum = User.preferens.AgePreference + User.preferens.GenderPreference + User.preferens.LocationPreference + User.preferens.RankPreference;

            List <string> Favorites = User.preferens.FavoriteSports;

            List <User> UpdatedUsers = new List <User>();
            //calculate euclidean distance between user to all other users
            var GOCL = new GoalsController();

            foreach (var CurrentUser in UsersList)
            {
                if (CurrentUser.Goals == null)
                {
                    CurrentUser.Goals = GOCL.GetRandomGoals();
                    Context.Users.Save(CurrentUser);
                }

                bool favoriteFlag = false;
                if (CurrentUser.preferens != null)
                {
                    for (int i = 0; i < CurrentUser.preferens.FavoriteSports.Count; i++)
                    {
                        if (Favorites.Contains(CurrentUser.preferens.FavoriteSports[i]))
                        {
                            favoriteFlag = true;
                            break;
                        }
                    }

                    if (CurrentUser.Email != User.Email &&
                        CurrentUser.Country.Equals(User.Country) && CurrentUser.preferens.Location.Equals(User.preferens.Location) && favoriteFlag)
                    {
                        double distanceAge      = powNumber((CurrentUser.Age - User.Age)) * User.preferens.AgePreference / sum;
                        double distanceLocation = (double)((CheckValue(CurrentUser.preferens.Location, User.preferens.Location)) * User.preferens.LocationPreference / sum);
                        double distanceGender   = (CheckValue(CurrentUser.Gender, User.Gender)) * User.preferens.GenderPreference / sum;
                        double distanceTime     = (CheckTime(User.preferens.Morning, CurrentUser.preferens.Morning, User.preferens.Noon, CurrentUser.preferens.Noon, User.preferens.Evening, CurrentUser.preferens.Evening)
                                                   ) * User.preferens.RankPreference / sum;
                        double distance = System.Math.Round(System.Math.Sqrt(distanceAge + distanceLocation + distanceGender + distanceTime), 0);



                        CurrentUser.distance = 100 - distance;
                        UpdatedUsers.Add(CurrentUser);
                    }
                }
            }
            return(View(UpdatedUsers));
        }
Пример #2
0
        public ActionResult Create(User user)
        {
            var GOCL = new GoalsController();


            if (ModelState.IsValid)
            {
                user.Goals = GOCL.GetRandomGoals();
                Context.Users.Insert(user);
                return(RedirectToAction("Index", "Login"));
            }
            return(View());
        }