예제 #1
0
        private static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new BudgetContext(
                       serviceProvider.GetRequiredService <DbContextOptions <BudgetContext> >(),
                       serviceProvider.GetRequiredService <IMediator>()))
            {
                if (context.Budgets.Any())
                {
                    return;
                }

                context.AddRange(GetTestBudget());

                context.SaveChanges();
            }
        }
예제 #2
0
        private void InsertSampleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "Web summit",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "Microsoft",
                    Location  = new Location
                    {
                        City     = "Krakow",
                        Street   = "Szeroka 33/5",
                        PostCode = "31-337"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Bob Clark",
                            Topic       = "Modern browsers",
                            Description = "Deep dive into V8"
                        }
                    }
                },
                new Meetup
                {
                    Name      = "4Devs",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "KGD",
                    Location  = new Location
                    {
                        City     = "Warszawa",
                        Street   = "Chmielna 33/5",
                        PostCode = "00-007"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Will Smith",
                            Topic       = "React.js",
                            Description = "Redux introduction"
                        },
                        new Lecture
                        {
                            Author      = "John Cena",
                            Topic       = "Angular store",
                            Description = "Ngxs in practice"
                        }
                    },
                },
            };

            var budgets = new List <Budget> {
                new Budget
                {
                    Name      = "Utilities",
                    costItems = new List <CostItem>
                    {
                        new CostItem
                        {
                            Name   = "electric",
                            Amount = 400.50,
                        },
                        new CostItem
                        {
                            Name   = "water",
                            Amount = 30.50,
                        },
                    }
                },
                new Budget
                {
                    Name      = "Food",
                    costItems = new List <CostItem>
                    {
                        new CostItem
                        {
                            Name   = "lunch",
                            Amount = 10.50,
                        },
                    }
                }
            };

            _budgetContext.AddRange(budgets);
            _budgetContext.AddRange(meetups);
            _budgetContext.SaveChanges();
        }