public static void Initialize(RewardingContext context) { context.Database.EnsureCreated(); // проверка на данные в таблице пользователей if (context.Users.Any()) { return; } var users = new User[] { new User { FirstName = "Alex", LastName = "Lucas", BirthDate = DateTime.Parse("13.11.1992") }, new User { FirstName = "Den", LastName = "Manford", BirthDate = DateTime.Parse("9.6.1988") }, new User { FirstName = "Max", LastName = "Ivanov", BirthDate = DateTime.Parse("10.9.1981") } }; foreach (User u in users) { context.Users.Add(u); } context.SaveChanges(); var awards = new Award[] { new Award { Title = "Nobel", Description = "Most important prize" }, new Award { Title = "Darvin", Description = "Not good for you" }, new Award { Title = "Contoso university award", Description = "For best of the best" } }; foreach (Award a in awards) { context.Awards.Add(a); } context.SaveChanges(); var rewardings = new Rewarding[] { new Rewarding { UserID = 1, AwardID = 1 }, new Rewarding { UserID = 1, AwardID = 2 } }; foreach (Rewarding r in rewardings) { context.Rewardings.Add(r); } context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RewardingContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public UsersController(RewardingContext context) { _context = context; }
public AwardsController(RewardingContext context) { _context = context; }