public async Task <IActionResult> PostLocationHistory([FromBody] MockDataInitializeContract data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = _httpContextAccessor.CurrentUserId(); var user = await _context.ApplicationUsers.FirstOrDefaultAsync(a => a.Email.Equals(data.Email, StringComparison.OrdinalIgnoreCase)); if (user == null) { return(NotFound(data.Email)); } if (!user.Id.Equals(userId)) { return(Unauthorized()); } if (user.AccountType != AccountType.MockedData) { return(Unauthorized()); } var dataseed = new MockDataInitializer(); await dataseed.InitializeMockUsers(_serviceProvider, data); return(Ok()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager, ApplicationDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); // Seed mock data MockDataInitializer.SeedMockData(userManager, dbContext); }
public List <Category> SetupCategories() { int counter = new int(); List <Category> categories = MockDataInitializer.GenerateCategories(); foreach (Category c in categories) { c.ID = ++counter; } return(categories); }
public List <Employee> SetupEmployees() { int counter = new int(); List <Employee> employees = MockDataInitializer.GenerateEmployees(); foreach (Employee e in employees) { e.ID = ++counter; } return(employees); }
//public List<Rental> SetupRentals() //{ // int counter = new int(); // List<Rental> rentals = MockDataInitializer.GenerateRentals(); // foreach (Rental rental in rentals) // rental.ID = ++counter; // return rentals; //} public List <Device> SetupDevices() { int counter = new int(); List <Device> devices = MockDataInitializer.GenerateDevices(); foreach (Device d in devices) { d.ID = ++counter; } return(devices); }
public List <Stock> SetupStocks() { int counter = new int(); List <Stock> stocks = MockDataInitializer.GenerateStocks(); foreach (Stock s in stocks) { s.ID = ++counter; } return(stocks); }
public List <Department> SetupDepartments() { int counter = new int(); List <Department> departments = MockDataInitializer.GenerateDepartments(); foreach (Department d in departments) { d.ID = ++counter; } return(departments); }
protected override void Seed(CompanyStore.Data.CompanyStoreContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // // Create Department context.Departments.AddOrUpdate(e => e.Name, MockDataInitializer.GenerateDepartments().ToArray()); // Create Employees context.Employees.AddOrUpdate(e => e.FirstName, MockDataInitializer.GenerateEmployees().ToArray()); // Create Genres context.Categories.AddOrUpdate(g => g.Name, MockDataInitializer.GenerateCategories().ToArray()); // Create Devices context.Devices.AddOrUpdate(d => d.Name, MockDataInitializer.GenerateDevices().ToArray()); // Create Stocks context.Stocks.AddOrUpdate(MockDataInitializer.GenerateStocks().ToArray()); // Create Roles context.Roles.AddOrUpdate(r => r.Name, MockDataInitializer.GenerateRoles().ToArray()); // Create Users context.Users.AddOrUpdate(u => u.Username, new User[] { new User() { Email = "*****@*****.**", FirstName = "Wanasak", LastName = "Suraintaranggoon", Username = "******", IsLocked = false, CreatedDate = DateTime.Now, HashedPassword = "******", Salt = "ljd/YZrfxnkEoB0l2rvjgA==", Image = "twitter-profile.jpg" } }); // Create user admin for smudger context.UserRoles.AddOrUpdate(new UserRole[] { new UserRole() { UserID = 1, RoleID = 1 } }); }
public List <Stock> SetupStocks() { int counter = new int(); List <Stock> stocks = MockDataInitializer.GenerateStocks(); foreach (Stock s in stocks) { s.ID = ++counter; } Stock firstStock = stocks.First(); firstStock.Rentals.Add(MockDataInitializer.GenerateRentals().First()); firstStock.Rentals.First().ID = 1; firstStock.Rentals.First().Stock = firstStock; firstStock.IsAvailable = false; return(stocks); }
public void Configuration(IAppBuilder appBuilder) { var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.MapHttpAttributeRoutes(); // Autofac configuration var builder = new ContainerBuilder(); // Unit od Work var unitOfWork = new Mock <IUnitOfWork>(); builder.RegisterInstance(unitOfWork.Object).As <IUnitOfWork>(); // Repositories var departmentRepository = new Mock <IEntityBaseRepository <Department> >(); departmentRepository.Setup(d => d.GetAll()).Returns( MockDataInitializer.GenerateDepartments().AsQueryable() ); builder.RegisterInstance(departmentRepository.Object).As <IEntityBaseRepository <Department> >(); // Services builder.RegisterAssemblyTypes(typeof(DepartmentService).Assembly) .Where(t => t.Name.EndsWith("Service")) .AsImplementedInterfaces().InstancePerRequest(); builder.RegisterInstance(new DepartmentService(departmentRepository.Object)); IContainer container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); appBuilder.UseWebApi(config); }
public static IWebHost Seed(this IWebHost host) { using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { Task.Run(async() => { #if DEBUG var dataseed = new MockDataInitializer(); await dataseed.InitializeMockUsers(serviceProvider); #endif }).Wait(); } catch (Exception ex) { var logger = serviceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } return(host); }