Esempio n. 1
0
 public Vote(User voter, Option option)
 {
     VoterId = voter.Id;
     Voter = voter;
     OptionId = OptionId;
     Option = option;
 }
Esempio 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;
 }
Esempio 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");
        }
Esempio 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);
            }
        }
Esempio n. 5
0
 public void Add(User user)
 {
     _context.Users.Add(user);
 }
Esempio n. 6
0
 public void VoteFor(User voter)
 {
     Vote newVote = new Vote(voter, this);
     Votes.Add(newVote);
 }
Esempio 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);
        }