Ejemplo n.º 1
0
        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 }));
            }
        }
Ejemplo n.º 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 }));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(CreateDraftViewModel model)
        {
            try
            {
                IDraftLogic draftLogic = GetDraftLogic.DefaultDraftLogic();

                using (var sl = new SystemLogic())
                {
                    var draft = draftLogic.CreateDraft(model.DraftName, GetAuthorizedMember().Id, model.MaximumNumberOfPicks, model.IsPublic);

                    return(RedirectToAction("Start", new { id = draft.Id }));
                }
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 4
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 }));
            }
        }
Ejemplo n.º 5
0
        public void CreateDebugData()
        {
            using (SystemLogic sl = new SystemLogic())
            {
                sl.CreateUser("Snidd", "*****@*****.**", "magnus", "Magnus Kjellberg");
                sl.CreateUser("Mats", "*****@*****.**", "mats", "Mats Törnros");
                sl.CreateUser("Rikard", "*****@*****.**", "rikard", "Rikard Stenlund");

                var dl = GetDraftLogic.DefaultDraftLogic();

                var member1 = sl.FindMember("Snidd");
                var member2 = sl.FindMember("Mats");
                var member3 = sl.FindMember("Rikard");

                var draft = dl.CreateDraft("Min draft", member1.Id, 75, true);

                dl.AddMemberToDraft(draft.Id, member1.Id, 1);
                dl.AddMemberToDraft(draft.Id, member2.Id, 2);
                dl.AddMemberToDraft(draft.Id, member3.Id, 3);

                dl.StartDraft(draft.Id, false);
            }
        }
Ejemplo n.º 6
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);
            }
        }