public ActionResult RemovePick(int id, string cardName)
        {
            var member = GetAuthorizedMember();

            using (var sl = new SystemLogic())
            {
                if (!sl.IsMemberOfDraft(member.Id, id))
                {
                    return(RedirectToAction("Index"));
                }

                List <FuturePick> futurePicks = sl.GetMyFuturePicks(id, member.Id);

                foreach (var futurePick in futurePicks)
                {
                    var card = sl.GetCard(futurePick.Card.Id);
                    if (card.Name.Equals(cardName))
                    {
                        sl.RemoveMyFuturePick(futurePick.Id);
                        return(Json(new { dvm = GetDraftViewModel(id), success = true }, JsonRequestBehavior.AllowGet));
                    }
                }

                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Pick(string cardName, int draftId)
        {
            var authMember = GetAuthorizedMember();

            using (var sl = new SystemLogic())
            {
                if (!sl.IsMemberOfDraft(authMember.Id, draftId))
                {
                    return(RedirectToAction("Index"));
                }

                var draftLogic = GetDraftLogic.FromDraftId(draftId);
                var card       = sl.GetCard(cardName);

                if (card == null)
                {
                    var likeList = sl.FindCard(cardName);
                    return(Json(new { pickresult = false, reason = "Card was not found!", alternatives = likeList }));
                }

                var pickSuccess = draftLogic.PickCard(draftId, authMember.Id, card.Id);

                if (!pickSuccess)
                {
                    return(Json(new { pickresult = false, reason = "Card was already picked, try another card!" }));
                }

                DraftViewModel dvm = GetDraftViewModel(draftId);

                return(Json(new { pickresult = true, updatedDvm = dvm }));
            }
        }
        private DraftViewModel GetDraftViewModel(int draftId)
        {
            var draftLogic  = GetDraftLogic.FromDraftId(draftId);
            var systemLogic = new SystemLogic();

            if (!draftLogic.IsDraftAvailable(draftId))
            {
                return(null);
            }

            var draft = systemLogic.GetDraftById(draftId);

            using (var sl = new SystemLogic())
            {
                var picks = systemLogic.GetPickList(draftId);
                var dvm   = new DraftViewModel
                {
                    Id = draftId,
                    MaximumNumberOfPicks = draft.MaximumPicksPerMember,
                    Name                 = draft.Name,
                    Owner                = sl.GetMember(draft.Owner.Id).FullName,
                    CreationDate         = draft.CreatedDate,
                    CurrentPickPosition  = draftLogic.CurrentPickPosition(draftId),
                    CurrentNumberOfPicks = picks.Count
                };

                var members = systemLogic.GetDraftMembers(draftId);

                foreach (var draftMemberPositions in members)
                {
                    var member        = sl.GetMember(draftMemberPositions.Member.Id);
                    var draftMemberVm = new DraftMemberVm
                    {
                        DisplayName = member.FullName,
                        Id          = member.Id,
                    };

                    dvm.Members.Add(draftMemberVm);
                }

                var pickCount  = picks.Count;
                var startIndex = pickCount - draft.DraftSize;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }

                for (int i = startIndex; i < pickCount; i++)
                {
                    var pick = picks[i];

                    var member = sl.GetMember(pick.Member.Id);
                    var card   = sl.GetCard(pick.Card.Id);

                    var pvm = new PickViewModel {
                        CardId = pick.Card.Id, MemberId = pick.Member.Id, PickTime = PickTime.History, CardName = card.Name, MemberName = member.FullName
                    };
                    dvm.Picks.Add(pvm);
                }

                var currentPick = new PickViewModel()
                {
                    MemberId   = draft.CurrentTurn.Id,
                    MemberName = sl.GetMember(draft.CurrentTurn.Id).FullName,
                    PickTime   = PickTime.Current,
                };
                dvm.Picks.Add(currentPick);

                for (int i = 0; i < draft.DraftSize; i++)
                {
                    var nextDraftPosition = draftLogic.GetNextPickPosition(pickCount + 1 + i, draft.DraftSize);
                    var nextMember        = dvm.Members[nextDraftPosition - 1];
                    var nextPick          = new PickViewModel
                    {
                        MemberName = nextMember.DisplayName,
                        MemberId   = nextMember.Id,
                        PickTime   = PickTime.Future
                    };

                    dvm.Picks.Add(nextPick);
                }

                var authMember = GetAuthorizedMember();
                if (authMember != null)
                {
                    foreach (FuturePick fp in sl.GetMyFuturePicks(draftId, authMember.Id))
                    {
                        Card card = sl.GetCard(fp.Card.Id);
                        dvm.FuturePicks.Add(card.Name);
                    }
                }

                return(dvm);
            }
        }