public void CanAddNewDraft()
        {
            var draft = new Draft
                            {
                                Name = "TestName",
                                CreatedDate = DateTime.Now,
                                MaximumPicksPerMember = 75,
                                Owner = _members[0],
            };

            IDraftRepository repository = new DraftRepository();
            repository.Add(draft);

            // use session to try to load the product
            using (var session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Draft>(draft.Id);
                // Test that the product was successfully inserted

                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(draft, fromDb);
                Assert.AreEqual(draft.Name, fromDb.Name);
                Assert.AreEqual(draft.Public, fromDb.Public);
                Assert.AreEqual(draft.Id, fromDb.Id);
                Assert.AreEqual(draft.Owner.Id, fromDb.Owner.Id);
                Assert.AreEqual(draft.MaximumPicksPerMember, fromDb.MaximumPicksPerMember);

                Assert.AreEqual(draft.CreatedDate.ToString(), fromDb.CreatedDate.ToString());
            }
        }
Beispiel #2
0
        public Chat AddChat(string message, int draftId, int memberId)
        {
            IChatRepository cr = new ChatRepository();
            IDraftRepository dr = new DraftRepository();
            IMemberRepository mr = new MemberRepository();

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

            var chat = new Chat() {Draft = draft, Member = member, Text = message};

            cr.Add(chat);

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

            try
            {
                var draft = dr.GetById(draftId);
                dmpr.AddMemberToDraft(draft, mr.GetById(memberId), draftPosition);
                draft.DraftSize++;
                dr.Update(draft);
                return true;
            }
            catch
            {
                return false;
            }
        }
        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 IsMyTurn(int draftId, int memberId)
        {
            IDraftRepository dr = new DraftRepository();
            var draft = dr.GetById(draftId);

            if (draft.CurrentTurn == null)
            {
                return false;
            }

            return draft.CurrentTurn.Id == memberId;
        }
 public bool IsDraftAvailable(int draftId)
 {
     IDraftRepository dr = new DraftRepository();
     var draft = dr.GetById(draftId);
     return draft != null;
 }
Beispiel #7
0
 public Draft GetDraftById(int draftId)
 {
     IDraftRepository dr = new DraftRepository();
     return dr.GetById(draftId);
 }
        public void CanUpdateExistingDraft()
        {
            var draft = _drafts[0];
            draft.Name = "Yellow Pear";
            IDraftRepository repository = new DraftRepository();
            repository.Update(draft);

            // use session to try to load the product
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Draft>(draft.Id);
                Assert.AreEqual(draft.Name, fromDb.Name);
            }
        }
        public void CanGetListFromName()
        {
            IDraftRepository repository = new DraftRepository();
            ICollection<Draft> appleDrafts = repository.GetByName("Apple");

            Assert.AreEqual(2, appleDrafts.Count);
        }
        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;
        }
Beispiel #11
0
        public List<Pick> GetPickList(int draftId)
        {
            IPickRepository pickRepository = new PickRepository();
            IDraftRepository dr = new DraftRepository();

            var draft = dr.GetById(draftId);
            var ret = pickRepository.GetPicksByDraft(draft);
            return ret == null ? new List<Pick>() : ret.ToList();
        }
Beispiel #12
0
        public List<FuturePick> GetMyFuturePicks(int draftId, int memberId)
        {
            IFuturePickRepository fpr = new FuturePickRepository();
            IDraftRepository dr = new DraftRepository();
            IMemberRepository mr = new MemberRepository();

            var draft = dr.GetById(draftId);
            var member = mr.GetById(memberId);
            var ret = fpr.GetFuturePicksByDraftAndMember(draft, member);
            return ret == null ? new List<FuturePick>() : ret.ToList();
        }
Beispiel #13
0
        public List<Pick> GetLatestPicksByPlayer(int draftId, int memberId)
        {
            IDraftRepository dr = new DraftRepository();
            IPickRepository pr = new PickRepository();
            IMemberRepository mr = new MemberRepository();

            var draft = dr.GetById(draftId);
            var member = mr.GetById(memberId);
            var picksCollection = pr.GetPicksByDraftAndMember(draft, member);

            if (picksCollection == null)
                return new List<Pick>();

            var picks = picksCollection.ToList();
            picks.Sort((p1, p2) => p1.CreatedDate.CompareTo(p2.CreatedDate));

            return picks;
        }
Beispiel #14
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();
        }
Beispiel #15
0
 public List<Draft> GetDraftList()
 {
     IDraftRepository dr = new DraftRepository();
     var ret = dr.ListActive();
     return ret == null ? new List<Draft>() : ret.ToList();
 }
        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;
        }
Beispiel #17
0
        public List<Chat> GetUpdatedChatList(int draftId, int latestChatId)
        {
            IChatRepository cr = new ChatRepository();
            IDraftRepository dr = new DraftRepository();

            var draft = dr.GetById(draftId);
            var res = cr.ListNewChatsFromDraft(draft, latestChatId);

            return res != null ? res.ToList() : new List<Chat>();
        }
        private void TryFuturePick(int draftId)
        {
            IDraftRepository dr = new DraftRepository();
            IFuturePickRepository fpr = new FuturePickRepository();

            var draft = dr.GetById(draftId);

            var futurePick = fpr.GetNextFuturePick(draft, draft.CurrentTurn);
            if (futurePick != null)
            {
                var futurePickCard = futurePick.Card;
                fpr.RemoveFuturePick(futurePick);

                PickCard(draftId, draft.CurrentTurn.Id, futurePickCard.Id);
            }
        }
Beispiel #19
0
        public bool IsCardPicked(int draftId, int cardId)
        {
            IPickRepository pr = new PickRepository();
            IDraftRepository dr = new DraftRepository();
            ICardRepository cr = new CardRepository();

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

            var picks = pr.GetPicksByCardAndDraft(card, draft);
            return picks.Count > 0;
        }
        public Draft CreateDraft(string draftName, int ownerId, int numberOfPicksPerPlayer, bool isPublic)
        {
            var draft = new Draft
                            {
                                Name = draftName,
                                CreatedDate = DateTime.Now,
                                MaximumPicksPerMember = numberOfPicksPerPlayer,
                                Public = isPublic,
                                Started = false,
                                Finished = false,
                          	};

            IDraftRepository dr = new DraftRepository();
            IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository();
            IMemberRepository mr = new MemberRepository();

            draft.Owner = mr.GetById(ownerId);
            draft.DraftSize = 0;

            dr.Add(draft);

            return draft;
        }
Beispiel #21
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);
        }
        public void CanRemoveExistingDraft()
        {
            var draft = _drafts[0];
            IDraftRepository repository = new DraftRepository();
            repository.Remove(draft);

            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Draft>(draft.Id);
                Assert.IsNull(fromDb);
            }
        }
        public int CurrentPickPosition(int draftId)
        {
            IDraftRepository dr = new DraftRepository();
            IDraftMemberPositionsRepository dpr = new DraftMemberPositionsRepository();
            var draft = dr.GetById(draftId);

            return dpr.GetDraftPosition(draft, draft.CurrentTurn);
        }
        public bool FuturePickCard(int draftId, int memberId, int cardId)
        {
            IFuturePickRepository fpr = new FuturePickRepository();
            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);

            try
            {
                fpr.FuturePickCard(draft, member, card);
            }
            catch (GenericADOException)
            {
                return false;
            }

            return true;
        }
Beispiel #25
0
        public List<Chat> GetChatList(int draftId)
        {
            IChatRepository cr = new ChatRepository();
            IDraftRepository dr = new DraftRepository();

            var draft = dr.GetById(draftId);
            var res = cr.ListByDraft(draft);

            return res != null ? res.ToList() : new List<Chat>();
        }