コード例 #1
0
        public LunchOptionViewModel(int pollId, LunchOption lo, IEnumerable<LunchVote> votes)
        {
            Id = lo.Id;
            PollId = pollId;
            Name = lo.Name;

            var vLookup = votes.ToLookup(v => v.Score, v => v.User.UserName);
            Upvotes = vLookup[1].OrderBy(n => n).ToList();
            Downvotes = vLookup[-1].OrderBy(n => n).ToList();
        }
コード例 #2
0
 public static void OnVote(int pollId, LunchOption option, IEnumerable<LunchVote> votes)
 {
     OnVote(new LunchOptionViewModel(pollId, option, votes));
 }
コード例 #3
0
 public async Task<LunchOption> GetOrAddOption(DatabaseContext dbContext, string name)
 {
     var option = await dbContext.LunchOptions.SingleOrDefaultAsync(o => o.Name == name);
     if (option == null)
     {
         option = new LunchOption { Name = name };
         dbContext.LunchOptions.Add(option);
     }
     return option;
 }