Ejemplo n.º 1
0
        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());
            }
        }
        public int GetDraftPosition(Draft draft, Member member)
        {
            var draftMemberPositions = GetDraftMemberPositionByDraftMember(draft, member);
            if (draftMemberPositions == null)
                return -1;

            return draftMemberPositions.Position;
        }
Ejemplo n.º 3
0
 public void Update(Draft draft)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     using (ITransaction transaction = session.BeginTransaction())
     {
         session.Update(draft);
         transaction.Commit();
     }
 }
Ejemplo n.º 4
0
        public void Add(Draft draft)
        {
            draft.CreatedDate = DateTime.Now;

            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(draft);
                transaction.Commit();
            }
        }
Ejemplo n.º 5
0
 public ICollection<Chat> ListByDraft(Draft draft)
 {
     using (var session = NHibernateHelper.OpenSession())
     {
         var chats = session
             .CreateCriteria(typeof (Chat))
             .Add(Restrictions.Eq("Draft", draft))
             .AddOrder(Order.Asc("CreatedDate"))
             .List<Chat>();
         return chats;
     }
 }
        public void AddMemberToDraft(Draft draft, Member member, int position)
        {
            var draftMemberPositions = new DraftMemberPositions
                                                            {Draft = draft, Member = member, Position = position};

            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(draftMemberPositions);
                transaction.Commit();
            }
        }
 public DraftMemberPositions GetDraftMemberPositionByDraftMember(Draft draft, Member member)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         var draftMemberPositions = session
             .CreateCriteria(typeof(DraftMemberPositions))
             .Add(Restrictions.Eq("Member", member))
             .Add(Restrictions.Eq("Draft", draft))
             .UniqueResult<DraftMemberPositions>();
         return draftMemberPositions;
     }
 }
Ejemplo n.º 8
0
        public FuturePick FuturePickCard(Draft draft, Member member, Card card)
        {
            var pick = new FuturePick() { Draft = draft, Member = member, Card = card };

            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(pick);
                transaction.Commit();
            }

            return pick;
        }
Ejemplo n.º 9
0
        public ICollection<Pick> GetPicksByDraftAndMember(Draft draft, Member member)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var picks = session
                    .CreateCriteria(typeof(Pick))
                    .Add(Restrictions.Eq("Draft", draft))
                    .Add(Restrictions.Eq("Member", member))
                    .List<Pick>();

                return picks;
            }
        }
Ejemplo n.º 10
0
        public ICollection<Pick> GetPicksByDraft(Draft draft)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var picks = session
                    .CreateCriteria(typeof(Pick))
                    .Add(Restrictions.Eq("Draft", draft))
                    .AddOrder(Order.Asc("Id"))
                    .List<Pick>();

                return picks;
            }
        }
Ejemplo n.º 11
0
        public ICollection<Pick> GetPicksByCardAndDraft(Card card, Draft draft)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var picks = session
                    .CreateCriteria(typeof(Pick))
                    .Add(Restrictions.Eq("Card", card))
                    .Add(Restrictions.Eq("Draft", draft))
                    .List<Pick>();

                return picks;
            }
        }
Ejemplo n.º 12
0
 public Pick GetPick(Draft draft, Member member, Card card)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         var pick = session
             .CreateCriteria(typeof(Pick))
             .Add(Restrictions.Eq("Member", member))
             .Add(Restrictions.Eq("Draft", draft))
             .Add(Restrictions.Eq("Card", card))
             .UniqueResult<Pick>();
         return pick;
     }
 }
        public ICollection<DraftMemberPositions> GetMemberPositionsByDraft(Draft draft)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var draftMemberPositions = session
                    .CreateCriteria(typeof(DraftMemberPositions))
                    .Add(Restrictions.Eq("Draft", draft))
                    .AddOrder(Order.Asc("Position"))
                    .List<DraftMemberPositions>();

                return draftMemberPositions;
            }
        }
Ejemplo n.º 14
0
        public FuturePick GetNextFuturePick(Draft draft, Member member)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var pick = session
                    .CreateCriteria(typeof (FuturePick))
                    .Add(Restrictions.Eq("Member", member))
                    .Add(Restrictions.Eq("Draft", draft))
                    .AddOrder(Order.Asc("CreatedDate"))
                    .List<FuturePick>();

                if (pick.Count > 0)
                    return pick[0];

                return null;
            }
        }
Ejemplo n.º 15
0
        public Pick PickCard(Draft draft, Member member, Card card)
        {
            var pick = new Pick() { Draft = draft, Member = member, Card = card, CreatedDate = DateTime.Now};

            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(pick);
                transaction.Commit();
            }

            return pick;
        }
Ejemplo n.º 16
0
 public void RemovePick(Draft draft, Member member, Card card)
 {
     var pick = GetPick(draft, member, card);
     RemovePick(pick);
 }
Ejemplo n.º 17
0
 public static IDraftLogic FromDraft(Draft draft)
 {
     return new ModifiedRotisserieDraftLogic();
 }
        public void UpdatePosition(Draft draft, Member member, int position)
        {
            var draftMemberPositions = GetDraftMemberPositionByDraftMember(draft, member);

            draftMemberPositions.Position = position;

            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Update(draftMemberPositions);
                transaction.Commit();
            }
        }
        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;
        }
        public void RemoveMemberFromDraft(Draft draft, Member member)
        {
            var draftMemberPositions = GetDraftMemberPositionByDraftMember(draft, member);

            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Delete(draftMemberPositions);
                transaction.Commit();
            }
        }