public void ConfigureServices(IServiceCollection services) { var options = new DbContextOptionsBuilder <MvcProjectContext>() .UseSqlServer(Configuration.GetConnectionString("AppConnection")) .Options; var context = new MvcProjectContext(options); context.Database.OpenConnection(); // this is where exception is thrown context.Database.EnsureCreated(); // Contexts services.AddDbContext <AppDbContext>( options => options.UseSqlServer(Configuration.GetConnectionString("AppConnection")) ); services.AddDbContext <MvcProjectContext>( options => options.UseSqlite("DataSource=:memory:") ); //services.AddDbContext<UserContext>(options => options.UseSqlServer(Configuration.GetConnectionString("UsersConnection"))); // Custom services services.AddTransient <IEmailService, EmailService>(); // Identity services.AddIdentity <User, IdentityRole>(config => { config.Password.RequiredLength = 6; config.Password.RequireDigit = true; config.Password.RequireNonAlphanumeric = false; config.Password.RequireUppercase = true; config.Password.RequireLowercase = true; config.User.RequireUniqueEmail = true; config.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; config.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30.0); config.Lockout.MaxFailedAccessAttempts = 5; }) .AddEntityFrameworkStores <AppDbContext>() .AddDefaultTokenProviders(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.SlidingExpiration = true; options.ExpireTimeSpan = new TimeSpan(0, 1, 0); }); // Other services.AddControllers(options => { }) .AddXmlSerializerFormatters() .AddNewtonsoftJson(); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddSwaggerDocument(); }
public CategoriesController(MvcProjectContext context, IMapper mapper) { _categoryDb = context; _mapper = mapper; if (!_categoryDb.Categories.Any()) { _ = PostCategory(new CategoryCreationModel { Name = "Electronics" }); _ = PostCategory(new CategoryCreationModel { Name = "Home" }); _ = PostCategory(new CategoryCreationModel { Name = "Sports" }); _ = PostCategory(new CategoryCreationModel { Name = "Clothes" }); _ = PostCategory(new CategoryCreationModel { Name = "Education" }); _ = PostCategory(new CategoryCreationModel { Name = "Transport" }); } }
public PropertyTaxTransactionsController(MvcProjectContext context) { _context = context; }
public WaterTransactionsController(MvcProjectContext context) { _context = context; }
public UsersController(MvcProjectContext context) { _context = context; }
public ManagerOverviewController(MvcProjectContext context) { _context = context; }
public ElectricityTransactionsController(MvcProjectContext context) { _context = context; }
public ContactApplicationsController(MvcProjectContext context) { _context = context; }