public bool StartDraft(int draftId, bool randomizeSeats)
        {
            IDraftRepository dr = new DraftRepository();
            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();

            var draft = dr.GetById(draftId);

            if (randomizeSeats)
            {
                var draftMembers = dmpr.GetMemberPositionsByDraft(draft).ToList();
                var rand = new Random();

                for (var i = 1; i <= draft.DraftSize; i++)
                {
                    var randomPlayer = rand.Next(0, draftMembers.Count - 1);
                    var member = draftMembers[randomPlayer].Member;
                    dmpr.UpdatePosition(draft, member, i);
                    draftMembers.RemoveAt(randomPlayer);
                }
            }

            var startingPlayer = dmpr.GetDraftMemberPositionByDraftAndPosition(draft, 1);

            draft.Started = true;
            draft.CurrentTurn = startingPlayer.Member;

            dr.Update(draft);

            return false;
        }
        public bool PickCard(int draftId, int memberId, int cardId)
        {
            if (!IsMyTurn(draftId, memberId))
            {
                return FuturePickCard(draftId, memberId, cardId);
            }

            IDraftRepository dr = new DraftRepository();
            IMemberRepository mr = new MemberRepository();
            ICardRepository cr = new CardRepository();

            var draft = dr.GetById(draftId);
            var member = mr.GetById(memberId);
            var card = cr.GetById(cardId);

            if (draft.Finished || !draft.Started)
            {
                return false;
            }

            IPickRepository pickRepository = new PickRepository();
            try
            {
                var pick = pickRepository.PickCard(draft, member, card);
            }
            catch (GenericADOException)
            {
                return false;
            }

            var picks = pickRepository.GetPicksByDraft(draft);

            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();
            var nextMemberDraftPosition = dmpr.GetDraftMemberPositionByDraftAndPosition(draft,
                                                                                        GetNextPickPosition(picks.Count, draft.DraftSize));

            draft.CurrentTurn = nextMemberDraftPosition.Member;

            IDraftRepository draftRepository = new DraftRepository();
            draftRepository.Update(draft);

            TryFuturePick(draftId);

            return true;
        }
        public void CanCreateDraftFixedPositions()
        {
            IDraftLogic draftLogic = new ModifiedRotisserieDraftLogic();
            var draft = draftLogic.CreateDraft("My Testdraft", _members[1].Id, 75, true);

            draftLogic.AddMemberToDraft(draft.Id, _members[0].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[1].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[2].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[3].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[4].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[5].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[6].Id);
            draftLogic.AddMemberToDraft(draft.Id, _members[7].Id);

            //draftLogic.PickCard(draft.Id, _members[0].Id, _cards[5].Id);
            //draftLogic.PickCard(draft.Id, _members[1].Id, _cards[11].Id);

            // use session to try to load the pick)
            using (var session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Draft>(draft.Id);

                // Test that the pick was successfully inserted
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(draft, fromDb);

                Assert.AreEqual(draft.Owner.Id, fromDb.Owner.Id);
                Assert.AreEqual(draft.MaximumPicksPerMember, fromDb.MaximumPicksPerMember);
                Assert.AreEqual(8, fromDb.DraftSize);

                IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();

                ICollection<DraftMemberPositions> testList = dmpr.GetMemberPositionsByDraft(draft);
                List<DraftMemberPositions> test = testList.ToList();

                var position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 4);
                Assert.AreEqual(_members[3].Id, position.Id);

                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 8);
                Assert.AreEqual(_members[7].Id, position.Id);
                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 7);
                Assert.AreEqual(_members[6].Id, position.Id);
                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 6);
                Assert.AreEqual(_members[5].Id, position.Id);
                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 5);
                Assert.AreEqual(_members[4].Id, position.Id);
                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 3);
                Assert.AreEqual(_members[2].Id, position.Id);
                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 2);
                Assert.AreEqual(_members[1].Id, position.Id);
                position = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb, 1);
                Assert.AreEqual(_members[0].Id, position.Id);

            }
        }
 public void CanGetPlayerFromPosition()
 {
     IDraftMemberPositionsRepository repository = new DraftMemberPositionsRepository();
     var pos = repository.GetDraftMemberPositionByDraftAndPosition(_drafts[0], 3);
     Assert.AreEqual(_members[2].Id, pos.Id);
 }
        public void CanCreateDraftRandomPositions()
        {
            IDraftLogic draftLogic = new ModifiedRotisserieDraftLogic();
            var draft1 = draftLogic.CreateDraft("My Testdraft", _members[1].Id, 75, true);

            for (var i = 0; i < 8; i++)
            {
                draftLogic.AddMemberToDraft(draft1.Id, _members[i].Id);
            }

            var draft2 = draftLogic.CreateDraft("My Testdraft 2", _members[2].Id, 75, true);
            for (var i = 0; i < 8; i++)
            {
                draftLogic.AddMemberToDraft(draft2.Id, _members[i].Id);
            }

            var draft3 = draftLogic.CreateDraft("My Testdraft 3", _members[2].Id, 75, true);
            for (var i = 0; i < 8; i++)
            {
                draftLogic.AddMemberToDraft(draft3.Id, _members[i].Id);
            }

            var draft4 = draftLogic.CreateDraft("My Testdraft 4", _members[2].Id, 75, true);
            for (var i = 0; i < 8; i++)
            {
                draftLogic.AddMemberToDraft(draft4.Id, _members[i].Id);
            }

            var draft5 = draftLogic.CreateDraft("My Testdraft 5", _members[2].Id, 75, true);
            for (var i = 0; i < 8; i++)
            {
                draftLogic.AddMemberToDraft(draft5.Id, _members[i].Id);
            }

            draftLogic.StartDraft(draft1.Id, true);
            draftLogic.StartDraft(draft2.Id, true);
            draftLogic.StartDraft(draft3.Id, true);
            draftLogic.StartDraft(draft4.Id, true);
            draftLogic.StartDraft(draft5.Id, true);

            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();

            // use session to try to load the pick
            using (var session = _sessionFactory.OpenSession())
            {
                var fromDb1 = session.Get<Draft>(draft1.Id);
                var fromDb2 = session.Get<Draft>(draft2.Id);
                var fromDb3 = session.Get<Draft>(draft3.Id);
                var fromDb4 = session.Get<Draft>(draft4.Id);
                var fromDb5 = session.Get<Draft>(draft5.Id);

                var position1 = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb1, 1);
                var position2 = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb2, 1);
                var position3 = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb3, 1);
                var position4 = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb4, 1);
                var position5 = dmpr.GetDraftMemberPositionByDraftAndPosition(fromDb5, 1);

                if (position1.Member.Id != position2.Member.Id || position1.Member.Id != position3.Member.Id
                    || position1.Member.Id != position4.Member.Id || position1.Member.Id != position5.Member.Id)
                {
                    return;
                }

                Assert.Fail("Someone should get different place");
            }
        }