Example #1
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            if (Request.IsAuthenticated)
            {
                CurrentUser = RavenSession.Load<User>(User.Identity.Name);

                if (CurrentUser == null)
                {
                    FormsAuthentication.SignOut();
                    filterContext.Result = new RedirectResult("/");
                }
                else
                {
                    if (CurrentUser.Gender == UserGender.Unknown || CurrentUser.GenderPreference == UserGender.Unknown || CurrentUser.GenderPreference == null)
                    {
                        ViewBag.ShowGenderModal = "true";
                    }
                    else
                    {
                        ViewBag.ShowGenderModal = "false";
                    }

                    UserId = CurrentUser.Id;
                }
            }
        }
Example #2
0
        private List<Crush.Candidate> CandidatesFor(User crusher, User target)
        {
            var targetFriendsList = RavenSession.Include<UserFriends>(x => x.FriendsIds).Load(target.Id.ToLongId());

            List<Crush.Candidate> candidates = new List<Crush.Candidate>();
            int friendsToTake = 5;

            if (target.GenderPreference == UserGender.Unknown || crusher.Gender == target.GenderPreference)
            {
                candidates.Add(new Crush.Candidate()
                {
                    Selected = false,
                    UserId = crusher.Id,
                    Name = crusher.Name
                });

                friendsToTake = 4;
            }

            Random rand = new Random();

            if (targetFriendsList != null)
            {
                var friends = RavenSession.Load<User>(targetFriendsList.FriendsIds).ToList();
                if (target.GenderPreference != UserGender.Unknown)
                {
                    friends = friends.Where(x => x.Gender == target.GenderPreference).ToList();
                }
                candidates.AddRange(
                    friends.OrderBy(x => rand.Next(friends.Count())).Take(friendsToTake)
                    .Select(x => new Crush.Candidate() {
                        Selected = false,
                        UserId = x.Id,
                        Name = x.Name
                    })
                );
            }

            var otherCandidates = RavenSession.Query<User>().Customize(x => x.RandomOrdering()).Take(10 - candidates.Count);

            if (target.GenderPreference != UserGender.Unknown)
            {
                otherCandidates = otherCandidates.Where(x => x.Gender == target.GenderPreference);
            }

            candidates.AddRange(otherCandidates.ToList().Select(x => new Crush.Candidate() { Name = x.Name, UserId = x.Id, Selected = false }));

            candidates.Shuffle();

            return candidates;
        }