public Database.Entities.Other.PollSelection Convert(string source, Database.Entities.Other.PollSelection destination, ResolutionContext context) { return(new Database.Entities.Other.PollSelection { Name = source }); }
public Models.Other.PollSelection Convert(Database.Entities.Other.PollSelection source, Models.Other.PollSelection destination, ResolutionContext context) { return(new Models.Other.PollSelection { Id = source.Id, Name = source.Name, Votes = source.Votes?.Select(vote => new IdAndNickNameUser { Id = vote.VotedByUserId, NickName = vote.VotedByUser.NickNames.Current() }), IsWinner = IsWinner(source) }); }
private static bool IsWinner(Database.Entities.Other.PollSelection pollSelection) { // no winner determined if poll is still open if (pollSelection.Poll.Created.AddDays(7) > DateTime.Now) { return(false); } var highestValue = pollSelection.Poll.Selections.Select(x => new KeyValuePair <int, int>(x.Id, x.Votes.Count)) .Select(x => x.Value) .Distinct() .OrderByDescending(x => x).First(); return(pollSelection.Votes.Count == highestValue); }