コード例 #1
0
        /// <summary>
        /// Gets the next poi.
        /// </summary>
        /// <param name="usertour">The usertour.</param>
        /// <returns></returns>
        public POI GetNextPOI(UserTour usertour)
        {
            //Get TourPOIs for tour and for all UserPOIs
            var userpois =
                DB.TourPOI.Join(DB.UserPOI, tp => tp.FK_POI, up => up.FK_POI, (tp, up) => new { TourPOI = tp, UserPOI = up })
                .Where((d) => d.TourPOI.FK_POI == d.UserPOI.FK_POI && d.UserPOI.FK_UserTour == usertour.Id)
                .Select(d => d.TourPOI);
            var tourpois = DB.TourPOI.Where(tp => tp.FK_Tour == usertour.FK_Tour);

            //Get the next POI by order that is in the tour but not in the UserPOIs yet
            var remainingTourPois = Enumerable.Except <TourPOI>(tourpois, userpois).OrderBy(tp => tp.Order);

            POI nextPoi;

            if (remainingTourPois.Any())
            {
                var poiID = remainingTourPois.First().FK_POI;

                //Get POI
                nextPoi = DB.POI.First(p => p.Id == poiID);
            }
            else
            {
                nextPoi = null;
            }

            return(nextPoi);
        }
コード例 #2
0
        public UserTourDTO GetActiveTour(int userID)
        {
            UserTour tour = _userTourRepo.GetActiveTour(userID);

            if (tour == null)
            {
                ThrowNoStartedTourException();
            }

            return(Mapper.Map <UserTourDTO>(tour));
        }
コード例 #3
0
        private void SetupActiveTourAndNextPOI(int userID, int userTourID, int nextPOIID)
        {
            var activeTour = new UserTour {
                Id = userTourID
            };
            var nextPOI = new POI {
                Id = nextPOIID, Coordinates = DbGeography.PointFromText("POINT(34 3)", 4326)
            };

            _userTourRepoMock.Setup(m => m.GetActiveTour(userID)).Returns(activeTour);
            _userPoiRepoMock.Setup(m => m.GetNextPOI(activeTour)).Returns(nextPOI);
        }
コード例 #4
0
        public async Task <IActionResult> RemoveMemberFromTourConfirmed(string id)
        {
            Tour tour = _context.Tours.Where(t => t.TourId.Equals(
                                                 HttpContext.Session.GetInt32("ChosenTourId"))).Include(t => t.UserTours).FirstOrDefault();

            UserTour usertour = tour.UserTours.Where(ut => ut.UserId.Equals(id)).First();

            tour.UserTours.Remove(usertour);

            await _context.SaveChangesAsync();

            return(RedirectToAction("TourPlayers", new { id = HttpContext.Session.GetInt32("ChosenTourId") }));
        }
コード例 #5
0
        private POI GetNextPOIInternal(UserTour userTour)
        {
            POI nextPOI = _userPOIRepo.GetNextPOI(userTour);

            if (nextPOI == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content = new StringContent("Tour doesn't have remaining POIs")
                };
                throw new HttpResponseException(resp);
            }
            return(nextPOI);
        }
コード例 #6
0
        private UserTour GetActiveTour(int userID)
        {
            UserTour userTour = _userTourRepo.GetActiveTour(userID);

            if (userTour == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content = new StringContent("User doesn't have a started tour")
                };
                throw new HttpResponseException(resp);
            }
            return(userTour);
        }
コード例 #7
0
        public RouteToPointOfInterestDTO StartUserTour(int userID, int tourID, double currentLatitude, double currentLongitude)
        {
            VerifyNoTourIsStarted(userID);
            _userTourRepo.StartUserTour(userID, tourID);
            UserTour activeTour = _userTourRepo.GetActiveTour(userID);
            POI      nextPOI    = _userPOIRepo.GetNextPOI(activeTour.Id);
            IEnumerable <CoordinateDTO> route = _geoLocationService.GetRoute(currentLatitude, currentLongitude,
                                                                             nextPOI.Coordinates.Latitude.Value,
                                                                             nextPOI.Coordinates.Longitude.Value);

            return(new RouteToPointOfInterestDTO {
                NextPOI = PointOfInterestDTO.Create().Compile()(nextPOI), RouteToNextPOI = route
            });
        }
コード例 #8
0
        public void TestThatTourGetsStartedCorrectly()
        {
            UserTour activeTour = null;
            POI      nextPOI    = new POI
            {
                Id            = 4,
                Name          = "POIName",
                Description   = "POIDesc",
                VisitDuration = 23,
                Coordinates   = DbGeography.PointFromText("POINT(49 23)", 4326)
            };

            _userTourRepoMock.Setup(m => m.GetActiveTour(1)).Returns((int userId) => activeTour);
            _userTourRepoMock.Setup(m => m.StartUserTour(1, 2)).Callback(() => activeTour = new UserTour {
                Id = 3
            });
            _userPoiRepoMock.Setup(m => m.GetNextPOI(3)).Returns(nextPOI);
            CoordinateDTO coordinate1 = new CoordinateDTO {
                Latitude = 14, Longitude = 39
            };
            CoordinateDTO coordinate2 = new CoordinateDTO {
                Latitude = 16, Longitude = 40
            };

            _geoLocationServiceMock.Setup(m => m.GetRoute(It.IsInRange(7.9, 8.1, Range.Inclusive),
                                                          It.IsInRange(84.9, 85.1, Range.Inclusive), It.IsInRange(22.9, 23.1, Range.Inclusive),
                                                          It.IsInRange(48.9, 49.1, Range.Inclusive)))
            .Returns(new CoordinateDTO[] { coordinate1, coordinate2 });

            RouteToPointOfInterestDTO routeToPointOfInterestDto = _target.StartUserTour(1, 2, 8, 85);

            Assert.IsNotNull(routeToPointOfInterestDto);
            Assert.IsNotNull(routeToPointOfInterestDto.NextPOI);
            Assert.IsNotNull(routeToPointOfInterestDto.RouteToNextPOI);
            Assert.AreEqual(nextPOI.Id, routeToPointOfInterestDto.NextPOI.Id);
            Assert.AreEqual(nextPOI.Description, routeToPointOfInterestDto.NextPOI.Description);
            Assert.AreEqual(nextPOI.VisitDuration, routeToPointOfInterestDto.NextPOI.VisitDuration);
            Assert.AreEqual(23.0, routeToPointOfInterestDto.NextPOI.Latitude, 0.1);
            Assert.AreEqual(49.0, routeToPointOfInterestDto.NextPOI.Longitude, 0.1);
            Assert.AreEqual(2.0, routeToPointOfInterestDto.RouteToNextPOI.Count());
            Assert.AreEqual(14.0, routeToPointOfInterestDto.RouteToNextPOI.ElementAt(0).Latitude, 0.1);
            Assert.AreEqual(39.0, routeToPointOfInterestDto.RouteToNextPOI.ElementAt(0).Longitude, 0.1);
            Assert.AreEqual(16.0, routeToPointOfInterestDto.RouteToNextPOI.ElementAt(1).Latitude, 0.1);
            Assert.AreEqual(40.0, routeToPointOfInterestDto.RouteToNextPOI.ElementAt(1).Longitude, 0.1);
        }
コード例 #9
0
        public void Seed(BetzerLigaContext ctx)
        {
            string password = "******";

            Byte[] passwordHashUser, passwordSaltUser;

            authenticationHelper.CreatePasswordHash(password, out passwordHashUser, out passwordSaltUser);

            User user1 = new User
            {
                Firstname    = "Mads",
                Lastname     = "Madsen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                Following    = new List <Follower>(),
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user2 = new User
            {
                Firstname    = "Lars",
                Lastname     = "Lars",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user3 = new User
            {
                Firstname    = "Frederik",
                Lastname     = "Frederiksen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = false,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user4 = new User
            {
                Firstname    = "Ole",
                Lastname     = "Olsen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user5 = new User
            {
                Firstname    = "John",
                Lastname     = "Johnsen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user6 = new User
            {
                Firstname    = "Erik",
                Lastname     = "Eriksen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };
            Tournament tour1 = new Tournament
            {
                Name           = "TournaTest",
                NumberOfRounds = 12,
                IsDone         = false,
                StartDate      = new DateTime(2019, 12, 4),
                EndDate        = new DateTime(2019, 12, 24),
                Rounds         = new List <Round>(),
                Participants   = new List <UserTour>()
            };
            Tournament tour2 = new Tournament
            {
                Name           = "Testing",
                NumberOfRounds = 12,
                IsDone         = false,
                StartDate      = new DateTime(2019, 11, 30),
                EndDate        = new DateTime(2020, 1, 24),
                Rounds         = new List <Round>(),
                Participants   = new List <UserTour>()
            };

            Round round1 = new Round
            {
                RoundNumber     = 1,
                Tournament      = tour1,
                TotalGoals      = 0,
                TippingDeadLine = new DateTime(2019, 11, 26),
                Matches         = new List <Match>(),
                RoundPoints     = new List <UserRound>()
            };
            Round round2 = new Round
            {
                RoundNumber     = 1,
                Tournament      = tour2,
                TotalGoals      = 0,
                TippingDeadLine = new DateTime(2019, 12, 20),
                Matches         = new List <Match>(),
                RoundPoints     = new List <UserRound>()
            };

            UserRound userRound1 = new UserRound
            {
                User       = user1,
                Round      = round1,
                UserPoints = 0
            };
            UserRound userRound2 = new UserRound
            {
                User       = user2,
                Round      = round1,
                UserPoints = 0
            };
            UserRound userRound3 = new UserRound
            {
                User       = user3,
                Round      = round1,
                UserPoints = 0
            };
            UserRound userRound4 = new UserRound
            {
                User       = user4,
                Round      = round2,
                UserPoints = 0
            };
            UserRound userRound5 = new UserRound
            {
                User       = user2,
                Round      = round2,
                UserPoints = 0
            };
            UserRound userRound6 = new UserRound
            {
                User       = user3,
                Round      = round2,
                UserPoints = 0
            };
            UserRound userRound7 = new UserRound
            {
                User       = user1,
                Round      = round2,
                UserPoints = 0
            };

            UserTour usertour1 = new UserTour
            {
                User            = user1,
                TotalUserPoints = 0
            };
            UserTour usertour2 = new UserTour
            {
                User            = user2,
                TotalUserPoints = 0
            };
            UserTour usertour3 = new UserTour
            {
                User            = user3,
                TotalUserPoints = 0
            };
            UserTour usertour4 = new UserTour
            {
                User            = user4,
                TotalUserPoints = 0
            };
            UserTour usertour5 = new UserTour
            {
                User            = user5,
                TotalUserPoints = 0
            };
            UserTour usertour6 = new UserTour
            {
                User            = user6,
                TotalUserPoints = 0
            };

            Match match1 = new Match()
            {
                HomeTeam   = "BIF",
                HomeScore  = 3,
                GuestTeam  = "FCK",
                GuestScore = 1,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match2 = new Match()
            {
                HomeTeam   = "OB",
                HomeScore  = 1,
                GuestTeam  = "FCK",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match3 = new Match()
            {
                HomeTeam   = "FCM",
                HomeScore  = 2,
                GuestTeam  = "FCK",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match4 = new Match()
            {
                HomeTeam   = "BIF",
                HomeScore  = 3,
                GuestTeam  = "FCM",
                GuestScore = 1,
                StartDate  = new DateTime(2019, 12, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match5 = new Match()
            {
                HomeTeam   = "OB",
                HomeScore  = 1,
                GuestTeam  = "BIF",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 12, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match6 = new Match()
            {
                HomeTeam   = "FCM",
                HomeScore  = 2,
                GuestTeam  = "OB",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 12, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };

            UserMatch tips1 = new UserMatch()
            {
                User        = user1,
                Match       = match1,
                HomeTip     = 3,
                GuestTip    = 1,
                Rating      = 1,
                TotalPoints = 0
            };
            UserMatch tips2 = new UserMatch()
            {
                User        = user1,
                Match       = match2,
                HomeTip     = 2,
                GuestTip    = 1,
                Rating      = 2,
                TotalPoints = 0
            };
            UserMatch tips3 = new UserMatch()
            {
                User        = user1,
                Match       = match3,
                HomeTip     = 3,
                GuestTip    = 3,
                Rating      = 3,
                TotalPoints = 0
            };
            UserMatch tips4 = new UserMatch()
            {
                User        = user2,
                Match       = match1,
                HomeTip     = 2,
                GuestTip    = 3,
                Rating      = 1,
                TotalPoints = 0
            };
            UserMatch tips5 = new UserMatch()
            {
                User        = user2,
                Match       = match2,
                HomeTip     = 1,
                GuestTip    = 1,
                Rating      = 2,
                TotalPoints = 0
            };
            UserMatch tips6 = new UserMatch()
            {
                User        = user2,
                Match       = match3,
                HomeTip     = 2,
                GuestTip    = 3,
                Rating      = 3,
                TotalPoints = 0
            };
            UserMatch tips7 = new UserMatch()
            {
                User        = user3,
                Match       = match1,
                HomeTip     = 4,
                GuestTip    = 5,
                Rating      = 1,
                TotalPoints = 0
            };
            UserMatch tips8 = new UserMatch()
            {
                User        = user3,
                Match       = match2,
                HomeTip     = 4,
                GuestTip    = 4,
                Rating      = 2,
                TotalPoints = 0
            };
            UserMatch tips9 = new UserMatch()
            {
                User        = user3,
                Match       = match3,
                HomeTip     = 5,
                GuestTip    = 4,
                Rating      = 3,
                TotalPoints = 0
            };

            tour1.Participants.Add(usertour1);
            tour1.Participants.Add(usertour2);
            tour1.Participants.Add(usertour3);
            tour2.Participants.Add(usertour1);
            tour2.Participants.Add(usertour2);
            tour2.Participants.Add(usertour3);
            tour2.Participants.Add(usertour4);


            round1.RoundPoints.Add(userRound1);
            round1.RoundPoints.Add(userRound2);
            round1.RoundPoints.Add(userRound3);
            round2.RoundPoints.Add(userRound4);
            round2.RoundPoints.Add(userRound5);
            round2.RoundPoints.Add(userRound6);
            round2.RoundPoints.Add(userRound7);

            match1.Tips.Add(tips1);
            match1.Tips.Add(tips4);
            match1.Tips.Add(tips7);
            match2.Tips.Add(tips2);
            match2.Tips.Add(tips5);
            match2.Tips.Add(tips8);
            match3.Tips.Add(tips3);
            match3.Tips.Add(tips6);
            match3.Tips.Add(tips9);

            user1 = ctx.Users.Add(user1).Entity;
            user2 = ctx.Users.Add(user2).Entity;
            user3 = ctx.Users.Add(user3).Entity;
            user4 = ctx.Users.Add(user4).Entity;
            user5 = ctx.Users.Add(user5).Entity;
            user6 = ctx.Users.Add(user6).Entity;

            ctx.Tournaments.Add(tour1);
            ctx.Tournaments.Add(tour2);

            ctx.Rounds.Add(round1);
            ctx.Rounds.Add(round2);

            ctx.Matches.Add(match1);
            ctx.Matches.Add(match2);
            ctx.Matches.Add(match3);
            ctx.Matches.Add(match4);
            ctx.Matches.Add(match5);
            ctx.Matches.Add(match6);



            ctx.SaveChanges();
        }
コード例 #10
0
        public void TestCalculateRoundForUserCalculatesCorrectPoints()
        {
            User user1 = new User()
            {
                Id          = 1,
                Firstname   = "Karl",
                Lastname    = "Bielsen",
                IsAdmin     = false,
                Email       = "*****@*****.**",
                Tips        = new List <UserMatch>(),
                Tournaments = new List <UserTour>(),
                RoundPoints = new List <UserRound>()
            };
            Tournament tour = new Tournament()
            {
                Id             = 1,
                Name           = "Tournament",
                NumberOfRounds = 14,
                IsDone         = false,
                Rounds         = new List <Round>(),
                Participants   = new List <UserTour>()
            };
            Round round = new Round()
            {
                Id           = 1,
                RoundNumber  = 1,
                TournamentId = 1,
                Tournament   = tour,
                TotalGoals   = 0,
                Matches      = new List <Match>(),
                RoundPoints  = new List <UserRound>()
            };
            Match match1 = new Match()
            {
                Id         = 1,
                HomeTeam   = "Home",
                HomeScore  = 3,
                GuestTeam  = "Guest",
                GuestScore = 1,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match2 = new Match()
            {
                Id         = 2,
                HomeTeam   = "Home",
                HomeScore  = 1,
                GuestTeam  = "Guest",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match3 = new Match()
            {
                Id         = 3,
                HomeTeam   = "Home",
                HomeScore  = 2,
                GuestTeam  = "Guest",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            UserMatch tips1 = new UserMatch()
            {
                Id       = 1,
                User     = user1,
                UserId   = 1,
                Match    = match1,
                MatchId  = 1,
                HomeTip  = 3,
                GuestTip = 1,
                Rating   = 1
            };
            UserMatch tips2 = new UserMatch()
            {
                Id       = 2,
                User     = user1,
                UserId   = 1,
                Match    = match2,
                MatchId  = 2,
                HomeTip  = 2,
                GuestTip = 1,
                Rating   = 2
            };
            UserMatch tips3 = new UserMatch()
            {
                Id       = 2,
                User     = user1,
                UserId   = 1,
                Match    = match3,
                MatchId  = 3,
                HomeTip  = 3,
                GuestTip = 3,
                Rating   = 3
            };
            UserTour ustour = new UserTour()
            {
                Id              = 1,
                Tournament      = tour,
                TournamentId    = 1,
                User            = user1,
                UserId          = 1,
                TotalUserPoints = 0
            };
            UserRound usRound = new UserRound()
            {
                Id         = 1,
                Round      = round,
                RoundId    = 1,
                User       = user1,
                UserId     = 1,
                UserPoints = 0
            };

            tour.Rounds.Add(round);
            tour.Participants.Add(ustour);
            round.Matches.Add(match1);
            round.Matches.Add(match2);
            round.Matches.Add(match3);
            round.RoundPoints.Add(usRound);
            user1.Tips.Add(tips1);
            user1.Tips.Add(tips2);
            user1.Tips.Add(tips3);
            match1.Tips.Add(tips1);
            match2.Tips.Add(tips2);
            match3.Tips.Add(tips3);
            user1.Tournaments.Add(ustour);
            user1.RoundPoints.Add(usRound);

            int             expectedResult   = 54;
            PointCalculator pointCalc        = new PointCalculator();
            int             totalRoundPoints = pointCalc.CalculateRoundForUser(round, user1);

            Assert.True(expectedResult == totalRoundPoints);
        }