public static void EnsureSeedForContext(this LotterySyndicateContext context)
        {
            if (context.LotteryTickets.Any())
            {
                return;
            }

            var startDate      = new DateTime(2018, 02, 06);
            var lotteryTickets = new List <LotteryTicket>();

            //generate some lottery lines!
            for (int i = 0; i < 3; i++)
            {
                var numberOfLines       = rand.Next(1, 5);
                var seedLotteryLinesSet = new List <LotteryLine>();

                while (seedLotteryLinesSet.Count < numberOfLines)
                {
                    seedLotteryLinesSet.Add(new LotteryLine()
                    {
                        LotteryNumbers = GenerateNumbers()
                    });
                }

                var ticketToAdd = new LotteryTicket()
                {
                    DrawDate     = startDate,
                    LotteryLines = seedLotteryLinesSet
                };

                lotteryTickets.Add(ticketToAdd);
                startDate = startDate.AddDays(-7);
            }

            context.LotteryTickets.AddRange(lotteryTickets);
            context.SaveChanges();
        }
Example #2
0
 public bool Save()
 {
     return(_context.SaveChanges() > 0);
 }