Ejemplo n.º 1
0
 public Vote(User voter, Option option)
 {
     VoterId = voter.Id;
     Voter = voter;
     OptionId = OptionId;
     Option = option;
 }
Ejemplo n.º 2
0
 public bool AlreadyVoted(User voter)
 {
     foreach(var option in Options)
     {
         if(option.Votes.Contains(new Vote(voter, option)))
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
        private ActionResult Register(string username)
        {
            try
            {
                var newuser = new User(username);

                _unitOfWork.UserRepository.Add(newuser);

                _unitOfWork.Save();

                FormsAuthentication.SetAuthCookie(username, true);
            }catch
            {
                //persist model state and refierct to index?
                throw;
            }

            return RedirectToAction("Index", "Question");
        }
Ejemplo n.º 4
0
        public Question(string text, List<string> options, User asker)
        {
            Id = Guid.NewGuid();

            Text = text;

            Options = new List<Option>();
            if (options == null || options.Count < 2 || options.Count > 4) throw new InvalidOptionsException();
            for (int i = 0; i < options.Count; i++)
            {
                Options.Add(new Option(i, options[i]));
            }

            Asker = asker;

            //Charge user for asking a question:
            if (!asker.ChargePoints(PRICE_FOR_ASKING))
            {
                throw new NotEnoughPointsException(asker.Points, PRICE_FOR_ASKING);
            }
        }
Ejemplo n.º 5
0
 public void Add(User user)
 {
     _context.Users.Add(user);
 }
Ejemplo n.º 6
0
 public void VoteFor(User voter)
 {
     Vote newVote = new Vote(voter, this);
     Votes.Add(newVote);
 }
Ejemplo n.º 7
0
        public void Vote(User voter, int option)
        {
            // 1. Check if user has not already voted
            if (AlreadyVoted(voter))
            {
                throw new AlreadyVotedException();
            }

            // 2. Register Vote:
            var chosenOption = Options.Where(opt => opt.Key == option).Single();

            chosenOption.VoteFor(voter);

            // 3. Reward Voter for voting:
            voter.AwardPoints(REWARD_FOR_VOTING);
        }