public bool AddMemberToDraft(int draftId, int memberId)
        {
            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();
            IDraftRepository dr = new DraftRepository();
            IMemberRepository mr = new MemberRepository();

            var draft = dr.GetById(draftId);

            ICollection<DraftMemberPositions> draftMembers = dmpr.GetMemberPositionsByDraft(draft);

            int newPosition = 0;
            bool foundPosition = true;

            while (foundPosition)
            {
                foundPosition = false;
                newPosition++;

                foreach (var draftMember in draftMembers)
                {
                    if (draftMember.Position == newPosition)
                    {
                        foundPosition = true;
                    }
                }

            }
            try
            {
                dmpr.AddMemberToDraft(draft, mr.GetById(memberId), newPosition);
                draft.DraftSize++;
                dr.Update(draft);
                return true;
            }
            catch
            {
                return false;
            }
        }
        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 void CanGetPlayerListFromDraft()
        {
            IDraftMemberPositionsRepository repository = new DraftMemberPositionsRepository();
            ICollection<DraftMemberPositions> draftMemberPositions = repository.GetMemberPositionsByDraft(_drafts[0]);

            Assert.AreEqual(4, draftMemberPositions.Count);
        }
예제 #4
0
        public bool IsMemberOfDraft(int memberId, int draftId)
        {
            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();
            IDraftRepository dr = new DraftRepository();

            var draft = dr.GetById(draftId);
            var memberPositions = dmpr.GetMemberPositionsByDraft(draft);

            return memberPositions.Any(memberPosition => memberPosition.Member.Id == memberId);
        }
예제 #5
0
        public List<DraftMemberPositions> GetDraftMembers(int draftId)
        {
            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();
            IDraftRepository dr = new DraftRepository();

            var draft = dr.GetById(draftId);

            var ret = dmpr.GetMemberPositionsByDraft(draft);
            return ret == null ? new List<DraftMemberPositions>() : ret.ToList();
        }
        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);

            }
        }