private void CreateColorAndSize(MyShopDBContext context) { if (context.Size.Count() == 0) { List <Size> ListSize = new List <Size>() { new Size() { SizeName = "XS", SizeValue = "XS" }, new Size() { SizeName = "S", SizeValue = "M" }, new Size() { SizeName = "L", SizeValue = "L" }, new Size() { SizeName = "XL ", SizeValue = "#ffffff" }, new Size() { SizeName = "XXL", SizeValue = "XXL" }, }; context.Size.AddRange(ListSize); } }
private void CreateUser(MyShopDBContext context) { var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new MyShopDBContext())); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new MyShopDBContext())); var user = new ApplicationUser() { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, FirstName = "Nguyen Van", LastName = "Tiep", Level = 1, JoinDate = DateTime.Now }; if (manager.Users.Count(x => x.UserName == "Administrator") == 0) { manager.Create(user, "Ab@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" }); } //if (context.ApplicationGroups.Count() == 0) //{ // ApplicationGroup group = new ApplicationGroup() // { // Name = "Administrator", // Description = "Nhóm quản trị hệ thống" // }; // context.ApplicationGroups.Add(group); // context.ApplicationGroups.Add(new ApplicationGroup() // { // Name = "Users", // Description = "Nhóm người dùng" // }); // context.SaveChanges(); // var adminUser = manager.FindByEmail("*****@*****.**"); // context.ApplicationUserGroups.Add(new ApplicationUserGroup() // { // UserId = adminUser.Id, // GroupId = group.ID // }); //} }
public UsersController(MyShopDBContext context) { _context = context; if (!_context.Users.Any()) { _context.Users.Add(new User { Name = "Tom", Password = "******", Role = "admin" }); _context.SaveChanges(); } }
private void Seed(MyShopDBContext context) { var categories = new[] { new Category { Name = "AAAA", IsActive = true }, new Category { Name = "BBBB", IsActive = true }, }; context.Categories.AddRange(categories); context.SaveChanges(); }
public void Test2() { var options = new DbContextOptionsBuilder <MyShopDBContext>() .UseInMemoryDatabase(databaseName: "DbMyShop") .Options; var context = new MyShopDBContext(options); Seed(context); var query = new CategoriesController(context); var result = query.Delete(1); Assert.True(result); }
public void Test1() { var options = new DbContextOptionsBuilder <MyShopDBContext>() .UseInMemoryDatabase(databaseName: "DbMyShop") .Options; var context = new MyShopDBContext(options); Seed(context); var query = new CategoriesController(context); var result = query.Execute(); Assert.Equal(2, result.Count); }
public MyShopDBContext Init() { return(context ?? (context = new MyShopDBContext())); }
public TagRepository(MyShopDBContext DBcontext) : base(DBcontext) { }
public UserCountryRepository(MyShopDBContext DBcontext) : base(DBcontext) { }
//The constructor accepts a database context instance and initializes the entity set variable: public GenericRepository(MyShopDBContext context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public ProductRepository(MyShopDBContext DBcontext) : base(DBcontext) { }
public MyShopDBContext Init() { return(dbcontext ?? (dbcontext = new MyShopDBContext())); //Nếu Null thì sẽ khởi tạo dbcontext }
public CategoryRepository(MyShopDBContext DBcontext) : base(DBcontext) { }
public ProductsController(MyShopDBContext context) { _context = context; }
public ApplicationUserStore(MyShopDBContext context) : base(context) { }
public CategoriesController(MyShopDBContext context) { _context = context; }