Example #1
0
        private bool UserVoted()
        {
            var userId = userProvider.GetId(this);

            if (userId == Guid.Empty)
            {
                return(false);
            }
            return(voteRepository.Contains(weekProvider.GetWeek(), userId));
        }
        public ActionResult Manage()
        {
            var userId = userProvider.GetId(this);
            var weekId = weekProvider.GetWeek();
            var result = voteRepository.CharactersPerWeek(weekId, userId);

            return(View(new ManageModel()
            {
                Characters = result
            }));
        }
        public RedirectResult SubmitVotes(string returnUrl)
        {
            var weekId = weekProvider.GetWeek();
            var userId = userProvider.GetId(this);
            var vote   = new Vote()
            {
                UserID = userId, WeekId = weekId
            };

            if (voteRepository.Contains(weekId, userId))
            {
                return(new RedirectResult(returnUrl));
            }

            var cart = GetCart();

            voteRepository.Add(vote, cart.CharactersIds);
            cartProvider.SetCart(this, new Cart());
            return(new RedirectResult(returnUrl));
        }
Example #4
0
        public ViewResult Checkout(VoteResults votes)
        {
            var userName    = UserProvider.GetUserName(this);
            var currentWeek = WeekProvider.GetWeek();

            if (repository.Votes.Any(x => x.Week == currentWeek && x.UserName == userName))
            {
                return(View(false));
            }
            repository.SaveVote(new Vote {
                UserName = userName, Week = currentWeek
            });
            var voteId = repository.Votes.FirstOrDefault(x => x.Week == currentWeek && x.UserName == userName).VoteId;

            foreach (var vote in votes.Votes)
            {
                repository.SaveVoteItem(new VoteItem()
                {
                    PersonId = vote.PersonId, VoteId = voteId
                });
            }
            return(View(true));
        }