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 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 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 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; }
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(); }
public Member GetMember(int memberId) { IMemberRepository mr = new MemberRepository(); return mr.GetById(memberId); }
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; }