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()); }
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); }