Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        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
            //    });
            //}
        }
Esempio n. 3
0
 public UsersController(MyShopDBContext context)
 {
     _context = context;
     if (!_context.Users.Any())
     {
         _context.Users.Add(new User {
             Name = "Tom", Password = "******", Role = "admin"
         });
         _context.SaveChanges();
     }
 }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 public MyShopDBContext Init()
 {
     return(context ?? (context = new MyShopDBContext()));
 }
 public TagRepository(MyShopDBContext DBcontext)
     : base(DBcontext)
 {
 }
Esempio n. 9
0
 public UserCountryRepository(MyShopDBContext DBcontext)
     : base(DBcontext)
 {
 }
Esempio n. 10
0
 //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>();
 }
Esempio n. 11
0
 public ProductRepository(MyShopDBContext DBcontext)
     : base(DBcontext)
 {
 }
Esempio n. 12
0
 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;
 }
Esempio n. 15
0
 public ApplicationUserStore(MyShopDBContext context)
     : base(context)
 {
 }
 public CategoriesController(MyShopDBContext context)
 {
     _context = context;
 }