public async Task Seed()
        {
            if (!_roleManager.Roles.Any())
            {
                await _roleManager.CreateAsync(new AppRole()
                {
                    Name           = "Admin",
                    NormalizedName = "Admin",
                    Description    = "Top manager"
                });

                await _roleManager.CreateAsync(new AppRole()
                {
                    Name           = "Staff",
                    NormalizedName = "Staff",
                    Description    = "Staff"
                });

                await _roleManager.CreateAsync(new AppRole()
                {
                    Name           = "Customer",
                    NormalizedName = "Customer",
                    Description    = "Customer"
                });
            }
            if (!_userManager.Users.Any())
            {
                await _userManager.CreateAsync(new AppUser()
                {
                    UserName             = "******",
                    FullName             = "Administrator",
                    Email                = "*****@*****.**",
                    CreatedDate          = DateTime.Now,
                    ModifiedDate         = DateTime.Now,
                    Status               = Status.Active,
                    Balance              = 0,
                    EmailConfirmed       = true,
                    PhoneNumberConfirmed = true
                }, "1234567aA@");

                var user = await _userManager.FindByNameAsync("admin");

                await _userManager.AddToRoleAsync(user, "Admin");
            }
            if (_context.Functions.Count() == 0)
            {
                _context.Functions.AddRange(new List <Function>()
                {
                    new Function()
                    {
                        Id = "SYSTEM", Name = "Hệ thống", ParentId = null, SortOrder = 1, Status = Status.Active, URL = "/", IconCss = "fa-desktop"
                    },
                    new Function()
                    {
                        Id = "ROLE", Name = "Nhóm", ParentId = "SYSTEM", SortOrder = 1, Status = Status.Active, URL = "/admin/role/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        Id = "FUNCTION", Name = "Chức năng", ParentId = "SYSTEM", SortOrder = 2, Status = Status.Active, URL = "/admin/function/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        Id = "USER", Name = "Người dùng", ParentId = "SYSTEM", SortOrder = 3, Status = Status.Active, URL = "/admin/user/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        Id = "ACTIVITY", Name = "Nhật ký", ParentId = "SYSTEM", SortOrder = 4, Status = Status.Active, URL = "/admin/activity/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        Id = "ERROR", Name = "Lỗi", ParentId = "SYSTEM", SortOrder = 5, Status = Status.Active, URL = "/admin/error/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        Id = "SETTING", Name = "Cấu hình", ParentId = "SYSTEM", SortOrder = 6, Status = Status.Active, URL = "/admin/setting/index", IconCss = "fa-home"
                    },
                    new Function()
                    {
                        Id = "PRODUCT", Name = "Sản phẩm", ParentId = null, SortOrder = 2, Status = Status.Active, URL = "/", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        Id = "PRODUCT_CATEGORY", Name = "Danh mục", ParentId = "PRODUCT", SortOrder = 1, Status = Status.Active, URL = "/admin/productcategory/index", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        Id = "PRODUCT_LIST", Name = "Sản phẩm", ParentId = "PRODUCT", SortOrder = 2, Status = Status.Active, URL = "/admin/product/index", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        Id = "BILL", Name = "Hóa đơn", ParentId = "PRODUCT", SortOrder = 3, Status = Status.Active, URL = "/admin/bill/index", IconCss = "fa-chevron-down"
                    },
                    new Function()
                    {
                        Id = "CONTENT", Name = "Nội dung", ParentId = null, SortOrder = 3, Status = Status.Active, URL = "/", IconCss = "fa-table"
                    },
                    new Function()
                    {
                        Id = "BLOG", Name = "Bài viết", ParentId = "CONTENT", SortOrder = 1, Status = Status.Active, URL = "/admin/blog/index", IconCss = "fa-table"
                    },
                    new Function()
                    {
                        Id = "UTILITY", Name = "Tiện ích", ParentId = null, SortOrder = 4, Status = Status.Active, URL = "/", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        Id = "FOOTER", Name = "Footer", ParentId = "UTILITY", SortOrder = 1, Status = Status.Active, URL = "/admin/footer/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        Id = "FEEDBACK", Name = "Phản hồi", ParentId = "UTILITY", SortOrder = 2, Status = Status.Active, URL = "/admin/feedback/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        Id = "ANNOUNCEMENT", Name = "Thông báo", ParentId = "UTILITY", SortOrder = 3, Status = Status.Active, URL = "/admin/announcement/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        Id = "CONTACT", Name = "Liên hệ", ParentId = "UTILITY", SortOrder = 4, Status = Status.Active, URL = "/admin/contact/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        Id = "SLIDE", Name = "Slide", ParentId = "UTILITY", SortOrder = 5, Status = Status.Active, URL = "/admin/slide/index", IconCss = "fa-clone"
                    },
                    new Function()
                    {
                        Id = "ADVERTISMENT", Name = "Quảng cáo", ParentId = "UTILITY", SortOrder = 6, Status = Status.Active, URL = "/admin/advertistment/index", IconCss = "fa-clone"
                    },

                    new Function()
                    {
                        Id = "REPORT", Name = "Báo cáo", ParentId = null, SortOrder = 5, Status = Status.Active, URL = "/", IconCss = "fa-bar-chart-o"
                    },
                    new Function()
                    {
                        Id = "REVENUES", Name = "Báo cáo doanh thu", ParentId = "REPORT", SortOrder = 1, Status = Status.Active, URL = "/admin/report/revenues", IconCss = "fa-bar-chart-o"
                    },
                    new Function()
                    {
                        Id = "ACCESS", Name = "Báo cáo truy cập", ParentId = "REPORT", SortOrder = 2, Status = Status.Active, URL = "/admin/report/visitor", IconCss = "fa-bar-chart-o"
                    },
                    new Function()
                    {
                        Id = "READER", Name = "Báo cáo độc giả", ParentId = "REPORT", SortOrder = 3, Status = Status.Active, URL = "/admin/report/reader", IconCss = "fa-bar-chart-o"
                    },
                });
            }

            if (_context.Footers.Count(x => x.Id == CommonConstants.DefaultFooterId) == 0)
            {
                string content = "Footer";
                _context.Footers.Add(new Footer()
                {
                    Id      = CommonConstants.DefaultFooterId,
                    Content = content
                });
            }

            if (_context.Colors.Count() == 0)
            {
                List <Color> listColor = new List <Color>()
                {
                    new Color()
                    {
                        Name = "Đen", Code = "#000000"
                    },
                    new Color()
                    {
                        Name = "Trắng", Code = "#FFFFFF"
                    },
                    new Color()
                    {
                        Name = "Đỏ", Code = "#ff0000"
                    },
                    new Color()
                    {
                        Name = "Xanh", Code = "#1000ff"
                    },
                };
                _context.Colors.AddRange(listColor);
            }
            if (_context.AdvertistmentPages.Count() == 0)
            {
                List <AdvertistmentPage> pages = new List <AdvertistmentPage>()
                {
                    new AdvertistmentPage()
                    {
                        Id = "home", Name = "Trang chủ", AdvertistmentPositions = new List <AdvertistmentPosition>()
                        {
                            new AdvertistmentPosition()
                            {
                                Id = "home-left", Name = "Bên trái"
                            }
                        }
                    },
                    new AdvertistmentPage()
                    {
                        Id = "product-cate", Name = "Danh mục sản phẩm",
                        AdvertistmentPositions = new List <AdvertistmentPosition>()
                        {
                            new AdvertistmentPosition()
                            {
                                Id = "product-cate-left", Name = "Bên trái"
                            }
                        }
                    },
                    new AdvertistmentPage()
                    {
                        Id = "product-detail", Name = "Chi tiết sản phẩm",
                        AdvertistmentPositions = new List <AdvertistmentPosition>()
                        {
                            new AdvertistmentPosition()
                            {
                                Id = "product-detail-left", Name = "Bên trái"
                            }
                        }
                    },
                };
                _context.AdvertistmentPages.AddRange(pages);
            }


            if (_context.Slides.Count() == 0)
            {
                List <Slide> slides = new List <Slide>()
                {
                    new Slide()
                    {
                        Name = "Slide 1", Image = "/client-side/images/slider/slide-1.jpg", Url = "#", DisplayOrder = 0, GroupAlias = "top", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 2", Image = "/client-side/images/slider/slide-2.jpg", Url = "#", DisplayOrder = 1, GroupAlias = "top", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 3", Image = "/client-side/images/slider/slide-3.jpg", Url = "#", DisplayOrder = 2, GroupAlias = "top", Status = true
                    },

                    new Slide()
                    {
                        Name = "Slide 1", Image = "/client-side/images/brand1.png", Url = "#", DisplayOrder = 1, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 2", Image = "/client-side/images/brand2.png", Url = "#", DisplayOrder = 2, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 3", Image = "/client-side/images/brand3.png", Url = "#", DisplayOrder = 3, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 4", Image = "/client-side/images/brand4.png", Url = "#", DisplayOrder = 4, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 5", Image = "/client-side/images/brand5.png", Url = "#", DisplayOrder = 5, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 6", Image = "/client-side/images/brand6.png", Url = "#", DisplayOrder = 6, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 7", Image = "/client-side/images/brand7.png", Url = "#", DisplayOrder = 7, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 8", Image = "/client-side/images/brand8.png", Url = "#", DisplayOrder = 8, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 9", Image = "/client-side/images/brand9.png", Url = "#", DisplayOrder = 9, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 10", Image = "/client-side/images/brand10.png", Url = "#", DisplayOrder = 10, GroupAlias = "brand", Status = true
                    },
                    new Slide()
                    {
                        Name = "Slide 11", Image = "/client-side/images/brand11.png", Url = "#", DisplayOrder = 11, GroupAlias = "brand", Status = true
                    },
                };
                _context.Slides.AddRange(slides);
            }


            if (_context.Sizes.Count() == 0)
            {
                List <Size> listSize = new List <Size>()
                {
                    new Size()
                    {
                        Name = "XXL"
                    },
                    new Size()
                    {
                        Name = "XL"
                    },
                    new Size()
                    {
                        Name = "L"
                    },
                    new Size()
                    {
                        Name = "M"
                    },
                    new Size()
                    {
                        Name = "S"
                    },
                    new Size()
                    {
                        Name = "XS"
                    }
                };
                _context.Sizes.AddRange(listSize);
            }

            if (_context.ProductCategories.Count() == 0)
            {
                List <ProductCategory> listProductCategory = new List <ProductCategory>()
                {
                    new ProductCategory()
                    {
                        Name     = "Áo nam", SeoAlias = "ao-nam", ParentId = null, Status = Status.Active, SortOrder = 1,
                        Products = new List <Product>()
                        {
                            new Product()
                            {
                                Name = "Sản phẩm 1", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-1", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 2", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-2", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 3", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-3", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 4", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-4", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 5", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-5", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                        }
                    },
                    new ProductCategory()
                    {
                        Name     = "Áo nữ", SeoAlias = "ao-nu", ParentId = null, Status = Status.Active, SortOrder = 2,
                        Products = new List <Product>()
                        {
                            new Product()
                            {
                                Name = "Sản phẩm 6", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-6", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 7", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-7", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 8", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-8", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 9", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-9", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 10", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-10", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                        }
                    },
                    new ProductCategory()
                    {
                        Name     = "Giày nam", SeoAlias = "giay-nam", ParentId = null, Status = Status.Active, SortOrder = 3,
                        Products = new List <Product>()
                        {
                            new Product()
                            {
                                Name = "Sản phẩm 11", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-11", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 12", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-12", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 13", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-13", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 14", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-14", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 15", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-15", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                        }
                    },
                    new ProductCategory()
                    {
                        Name     = "Giày nữ", SeoAlias = "giay-nu", ParentId = null, Status = Status.Active, SortOrder = 4,
                        Products = new List <Product>()
                        {
                            new Product()
                            {
                                Name = "Sản phẩm 16", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-16", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 17", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-17", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 18", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-18", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 19", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-19", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                            new Product()
                            {
                                Name = "Sản phẩm 20", Image = "/client-side/images/products/product-1.jpg", SeoAlias = "san-pham-20", Price = 1000, Status = Status.Active, OriginalPrice = 1000
                            },
                        }
                    }
                };
                _context.ProductCategories.AddRange(listProductCategory);
            }

            if (!_context.SystemConfigs.Any(x => x.Id == "HomeTitle"))
            {
                _context.SystemConfigs.Add(new SystemConfig()
                {
                    Id     = "HomeTitle",
                    Name   = "Tiêu đề trang chủ",
                    Value1 = "Trang chủ TeduShop",
                    Status = Status.Active
                });
            }
            if (!_context.SystemConfigs.Any(x => x.Id == "HomeMetaKeyword"))
            {
                _context.SystemConfigs.Add(new SystemConfig()
                {
                    Id     = "HomeMetaKeyword",
                    Name   = "Từ khoá trang chủ",
                    Value1 = "Trang chủ TeduShop",
                    Status = Status.Active
                });
            }
            if (!_context.SystemConfigs.Any(x => x.Id == "HomeMetaDescription"))
            {
                _context.SystemConfigs.Add(new SystemConfig()
                {
                    Id     = "HomeMetaDescription",
                    Name   = "Mô tả trang chủ",
                    Value1 = "Trang chủ TeduShop",
                    Status = Status.Active
                });
            }
            _context.SaveChanges();
        }
Exemple #2
0
 public void Commit()
 {
     _context.SaveChanges();
 }