상속: IBadgeRepository
예제 #1
0
        public ActionResult SeenMovie(int id)
        {
            Seen seen = new Seen();
            seen.MovieID = id;
            seen.UserID = User.Identity.Name;

            _seenRepository.Add(seen);
            _seenRepository.Save();

            BadgeRepository badgeRepository = new BadgeRepository();
            badgeRepository.CheckForBadges(User.Identity.Name);

            return Content("Got it!");
        }
예제 #2
0
        //Handle badges
        public void CheckForBadges(string user)
        {
            BadgeRepository badgeRep = new BadgeRepository();
            MovieRepository movieRep = new MovieRepository();
            List<Movie> userMovies = movieRep.GetMoviesByUser(user).ToList();
            List<Movie> movies = db.Movies.ToList();

            //1 = seen 100
            //2 = seen 50
            //3 = seen 250
            //4 = seen top 20
            //5 = seen top 10
            //6 = seen top 50
            if (userMovies.Count() >= 50)
            {
                BadgeList badgeList = new BadgeList { BadgeID = 2, UserID = user };
                badgeRep.Add(badgeList);
                badgeRep.Save();
            }
            if (userMovies.Count() >= 100)
            {
                BadgeList badgeList = new BadgeList { BadgeID = 1, UserID = user };
                badgeRep.Add(badgeList);
                badgeRep.Save();
            }
            if (userMovies.Count() == 250)
            {
                BadgeList badgeList = new BadgeList { BadgeID = 3, UserID = user };
                badgeRep.Add(badgeList);
                badgeRep.Save();
            }

            int i = 1;
            foreach (var movie in userMovies)
            {
                if (movie.Rank == i)
                {
                    if (i == 10)
                    {
                        BadgeList badgeList = new BadgeList { BadgeID = 5, UserID = user };
                        badgeRep.Add(badgeList);
                        badgeRep.Save();
                    }
                    if (i == 20)
                    {
                        BadgeList badgeList = new BadgeList { BadgeID = 4, UserID = user };
                        badgeRep.Add(badgeList);
                        badgeRep.Save();
                    }
                    if (i == 50)
                    {
                        BadgeList badgeList = new BadgeList { BadgeID = 6, UserID = user };
                        badgeRep.Add(badgeList);
                        badgeRep.Save();
                    }
                }
                else
                {
                    break;
                }
                i++;
            }
        }