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 bool IsDraftAvailable(int draftId) { IDraftRepository dr = new DraftRepository(); var draft = dr.GetById(draftId); return(draft != null); }
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 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>()); }
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()); }
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 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>()); }
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 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 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 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 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); }
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); } }
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 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); }
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 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 GetDraftById(int draftId) { IDraftRepository dr = new DraftRepository(); return(dr.GetById(draftId)); }