コード例 #1
0
        public AttendeeWinner RandomizeAttendeeAndSave(double eventId, string ruffleName)
        {
            var      attendee = GetAttendees(eventId);
            bool     find     = false;
            Attendee winner;
            var      winners = storageWinner.GetWinners(eventId).ToList();

            do
            {
                int position = random.Next(0, attendee.Count);
                winner = attendee.ElementAt(position);
                if (!winners.Any(t => t.Id == winner.Id))
                {
                    find = true;
                }
            } while (!find);

            var attendeeWinner = new AttendeeWinner
            {
                Attendee   = winner,
                EventId    = eventbriteConfig.EventId,
                RuffleName = ruffleName
            }
            .SetAttendee(winner);

            storageWinner.InsertWinner(attendeeWinner);

            return(attendeeWinner);
        }
コード例 #2
0
        public void InsertWinner(AttendeeWinner attendeeWinner)
        {
            var db  = Database.Value;
            var col = db.GetCollection <AttendeeWinner>(options.CollectionName);

            if (col.Count() > 0)
            {
                attendeeWinner.Incremental = col.Max(t => t.Incremental) + 1;
            }
            else
            {
                attendeeWinner.Incremental = 1;
            }

            col.Insert(attendeeWinner);
            col.EnsureIndex(x => x.Id);
            db.Checkpoint();
        }