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; }
public void Update(Draft draft) { using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Update(draft); transaction.Commit(); } }
public void Add(Draft draft) { draft.CreatedDate = DateTime.Now; using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Save(draft); transaction.Commit(); } }
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; } }
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; }
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; } }
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; } }
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; } }
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; } }
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; } }
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; }
public void RemovePick(Draft draft, Member member, Card card) { var pick = GetPick(draft, member, card); RemovePick(pick); }
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(); } }