public static WebShopDbContext InMemoryDatabase()
        {
            var dbOptions = new DbContextOptionsBuilder().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db        = new WebShopDbContext(dbOptions);

            return(db);
        }
Example #2
0
 private void CreateProductCategorySample(WebShopDbContext context)
 {
     if (context.ProductCategories.Count() == 0)
     {
         List <ProductCategory> listProductCategory = new List <ProductCategory>()
         {
             new ProductCategory()
             {
                 Name = "Pháo khói màu", Alias = "phao-khoi-mau", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 1
             },
             new ProductCategory()
             {
                 Name = "Pháo điện", Alias = "phao-dien", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 2
             },
             new ProductCategory()
             {
                 Name = "Các loại pháo khác", Alias = "cac-loai-phao-khac", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 3
             },
             new ProductCategory()
             {
                 Name = "Thiết bị sân khấu", Alias = "thiet-bi-san-khau", Status = true, CreatedDate = DateTime.Now, HomeFlag = true, DisplayOrder = 4
             },
         };
         context.ProductCategories.AddRange(listProductCategory);
         context.SaveChanges();
     }
 }
Example #3
0
        protected override void Seed(WebShopDbContext 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.
            //CreateProductCategorySample(context);

            //var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new WebShopDbContext()));

            //var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new WebShopDbContext()));

            //var user = new ApplicationUser()
            //{
            //    UserName = "******",
            //    Email = "*****@*****.**",
            //    EmailConfirmed = true,
            //    BirthDay = DateTime.Now,
            //    FullName = "Sương Gió Hà Nội",
            //};

            //manager.Create(user, "123456$");

            //if (!roleManager.Roles.Any())
            //{
            //    roleManager.Create(new IdentityRole { Name = "Admin" });
            //    roleManager.Create(new IdentityRole { Name = "User" });
            //}

            //var adminUser = manager.FindByEmail("*****@*****.**");

            //manager.AddToRoles(adminUser.Id, new string[] { "Admin", "User" });
        }
Example #4
0
 public UnitOfWork(WebShopDbContext context)
 {
     _context     = context;
     Product      = new ProductRepository(context);
     Order        = new OrderRepository(context);
     ShoppingCart = context.ShoppingCartItems;
     OrderDetail  = new OrderDetailRepository(context);
 }
Example #5
0
 public IndexModel(
     UserManager <WebShopUser> userManager,
     SignInManager <WebShopUser> signInManager,
     WebShopDbContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     this.context   = context;
 }
Example #6
0
 protected void UsingDbContext(int?tenantId, Action <WebShopDbContext> action)
 {
     using (UsingTenantId(tenantId))
     {
         using (WebShopDbContext context = LocalIocManager.Resolve <WebShopDbContext>())
         {
             action(context);
             context.SaveChanges();
         }
     }
 }
Example #7
0
        public static void SeedHostDb(WebShopDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
Example #8
0
        protected async Task UsingDbContextAsync(int?tenantId, Func <WebShopDbContext, Task> action)
        {
            using (UsingTenantId(tenantId))
            {
                using (WebShopDbContext context = LocalIocManager.Resolve <WebShopDbContext>())
                {
                    await action(context);

                    await context.SaveChangesAsync();
                }
            }
        }
Example #9
0
 public RegisterModel(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     ILogger <RegisterModel> logger,
     IEmailSender emailSender,
     WebShopDbContext _db)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _logger        = logger;
     _emailSender   = emailSender;
     db             = _db;
 }
Example #10
0
        protected T UsingDbContext <T>(int?tenantId, Func <WebShopDbContext, T> func)
        {
            T result;

            using (UsingTenantId(tenantId))
            {
                using (WebShopDbContext context = LocalIocManager.Resolve <WebShopDbContext>())
                {
                    result = func(context);
                    context.SaveChanges();
                }
            }

            return(result);
        }
Example #11
0
        protected async Task <T> UsingDbContextAsync <T>(int?tenantId, Func <WebShopDbContext, Task <T> > func)
        {
            T result;

            using (UsingTenantId(tenantId))
            {
                using (WebShopDbContext context = LocalIocManager.Resolve <WebShopDbContext>())
                {
                    result = await func(context);

                    await context.SaveChangesAsync();
                }
            }

            return(result);
        }
Example #12
0
 public WebShopDbContext Init()
 {
     return(dbContext ?? (dbContext = new WebShopDbContext()));
 }
Example #13
0
 public ManageProductService(WebShopDbContext context)
 {
     _context = context;
 }
 public HomeController(ILogger <HomeController> logger, WebShopDbContext dbContext)
 {
     _logger    = logger;
     _dbContext = dbContext;
 }
 public PublicProductService(WebShopDbContext context)
 {
     _context = context;
 }
Example #16
0
 public CustomerRepository(WebShopDbContext ctx)
 {
     _ctx = ctx;
 }
Example #17
0
 public PurchaseController(WebShopDbContext _db, UserManager <ApplicationUser> _um, CartService _cService)
 {
     db       = _db;
     um       = _um;
     cService = _cService;
 }
 public OrderRepository(WebShopDbContext ctx)
 {
     _ctx = ctx;
 }
Example #19
0
 public ItemService(WebShopDbContext dbContext)
 {
     this.context = dbContext;
 }
 public DefaultTenantBuilder(WebShopDbContext context)
 {
     _context = context;
 }
 public ItemsApiController(WebShopDbContext context)
 {
     _context = context;
 }
Example #22
0
 public AdminController(WebShopDbContext context)
 {
     _context = context;
 }
Example #23
0
 public CartController(WebShopDbContext _db, CartService _cService)
 {
     db       = _db;
     cService = _cService;
     cart     = cService.ReadCart();
 }
 public TenantRoleAndUserBuilder(WebShopDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
 public DefaultEditionCreator(WebShopDbContext context)
 {
     _context = context;
 }
Example #26
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <WebShopUser> userManager, RoleManager <IdentityRole <Guid> > roleManager, WebShopDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            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.UseAuthentication();


            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            //TODO: So ugly, debug thread issue with dbcontext error in SeedUsers
            UserSeeder.SeedUsers(userManager, roleManager, context).Wait();
        }
 public TagsController(WebShopDbContext context)
 {
     _context = context;
 }
Example #28
0
 public IsUserAdminService(WebShopDbContext dbContext, UserManager <AppUser> userManager, IHttpContextAccessor accessor)
 {
     _dbContext   = dbContext;
     _userManager = userManager;
     _accessor    = accessor;
 }
Example #29
0
 public HomeController(WebShopDbContext _db)
 {
     db = _db;
 }
Example #30
0
 public UserService(Dal.Context.WebShopDbContext dbContext)
 {
     this.context = dbContext;
 }