예제 #1
0
        public ActionResult Start(int id)
        {
            using (var sl = new SystemLogic())
            {
                var authMember = GetAuthorizedMember();
                var draft      = sl.GetDraftById(id);

                if (draft.Owner.Id != authMember.Id || draft.Started || draft.Finished)
                {
                    return(RedirectToAction("Index"));
                }

                var startDraftVm = new StartDraftViewModel {
                    DraftName = draft.Name, DraftId = draft.Id
                };
                var draftMemberPositions = sl.GetDraftMembers(draft.Id);

                foreach (var dfs in draftMemberPositions)
                {
                    var member = sl.GetMember(dfs.Member.Id);
                    startDraftVm.DraftMembers.Add(new DraftMemberViewModel
                    {
                        DraftPosition = dfs.Position,
                        Email         = member.Email,
                        FullName      = member.FullName
                    });
                }

                return(View(startDraftVm));
            }
        }
예제 #2
0
        public ActionResult Start(StartDraftViewModel model)
        {
            using (var sl = new SystemLogic())
            {
                var authMember = GetAuthorizedMember();
                var draft      = sl.GetDraftById(model.DraftId);

                if (draft.Owner.Id != authMember.Id || draft.Started || draft.Finished)
                {
                    return(RedirectToAction("Index"));
                }

                var dl = GetDraftLogic.FromDraft(draft);
                dl.StartDraft(draft.Id, model.RandomizeSeats);

                return(RedirectToAction("Details", new { id = draft.Id }));
            }
        }
예제 #3
0
        public ActionResult AddMember(string memberIdentification, int id)
        {
            using (var sl = new SystemLogic())
            {
                var authMember = GetAuthorizedMember();
                var draft      = sl.GetDraftById(id);

                if (draft.Owner.Id != authMember.Id)
                {
                    return(RedirectToAction("Index"));
                }

                var dl = GetDraftLogic.FromDraft(draft);

                var member = sl.FindMember(memberIdentification);
                if (member != null)
                {
                    dl.AddMemberToDraft(draft.Id, member.Id);
                }

                return(RedirectToAction("Start", new { id = draft.Id }));
            }
        }
예제 #4
0
        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);
            }
        }