Ejemplo n.º 1
0
        public static void CrateNccWebSite(NccDbContext dbContext, WebSiteInfo webSiteInfo)
        {
            var webSiteRepository     = new NccWebSiteRepository(dbContext);
            var webSiteInfoRepository = new NccWebSiteInfoRepository(dbContext);
            var webSiteService        = new NccWebSiteService(webSiteRepository, webSiteInfoRepository);
            var webSite = new NccWebSite()
            {
                Name = webSiteInfo.SiteName,
                AllowRegistration = true,
                DateFormat        = "dd/MM/yyyy",
                TimeFormat        = "hh:mm:ss",
                EmailAddress      = webSiteInfo.Email,
                Language          = webSiteInfo.Language,
                NewUserRole       = "Subscriber",
                TimeZone          = "UTC_6",
            };

            webSite.WebSiteInfos = new List <NccWebSiteInfo>();
            webSite.WebSiteInfos.Add(new NccWebSiteInfo()
            {
                Language  = webSiteInfo.Language,
                Name      = webSiteInfo.SiteName,
                SiteTitle = webSiteInfo.SiteName,
                Tagline   = webSiteInfo.Tagline
            });

            webSiteService.Save(webSite);
        }
Ejemplo n.º 2
0
        public static async Task <NccUser> CreateSuperAdminUser(
            NccDbContext nccDbContext,
            UserManager <NccUser> userManager,
            RoleManager <NccRole> roleManager,
            SignInManager <NccUser> signInManager,
            WebSiteInfo setupInfo
            )
        {
            CreateCmsDefaultRoles(nccDbContext, roleManager);
            NccRole superAdmin = await roleManager.FindByNameAsync(NccCmsRoles.SuperAdmin);

            if (superAdmin != null)
            {
                var adminUser = new NccUser()
                {
                    Email    = setupInfo.Email,
                    FullName = "Site Super Admin",
                    Name     = "Super Admin",
                    UserName = setupInfo.AdminUserName,
                };

                await userManager.CreateAsync(adminUser, setupInfo.AdminPassword);

                NccUser user = await userManager.FindByNameAsync(setupInfo.AdminUserName);

                await userManager.AddToRoleAsync(user, NccCmsRoles.SuperAdmin);

                return(user);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private static void CreateCmsDefaultRoles(NccDbContext nccDbContext, RoleManager <NccRole> roleManager)
        {
            var nccPermissionService = new NccPermissionService(new NccPermissionRepository(nccDbContext), new NccPermissionDetailsRepository(nccDbContext));
            var administrator        = CreatePermissionObject("Administrator");
            var manager     = CreatePermissionObject("Manager");
            var editor      = CreatePermissionObject("Editor");
            var author      = CreatePermissionObject("Author");
            var contributor = CreatePermissionObject("Contributor");
            var subscriber  = CreatePermissionObject("Subscriber");

            nccPermissionService.Save(
                new List <NccPermission>()
            {
                administrator,
                manager,
                editor,
                author,
                contributor,
                subscriber
            }
                );

            NccRole superAdmin = new NccRole()
            {
                Name = NccCmsRoles.SuperAdmin, NormalizedName = NccCmsRoles.SuperAdmin
            };
            var sa = roleManager.CreateAsync(superAdmin).Result;
        }
Ejemplo n.º 4
0
        //public static void CreateWebSite(NccDbContext dbContext, WebSiteInfo setupInfo)
        //{
        //    var webSiteRepository = new NccWebSiteRepository(dbContext);
        //    var webSiteInfoRepository = new NccWebSiteInfoRepository(dbContext);

        //    var webSiteService = new NccWebSiteService(webSiteRepository, webSiteInfoRepository);
        //    var webSite = new NccWebSite()
        //    {
        //        AllowRegistration = true,
        //        //Copyrights = "Copyright (c) " + DateTime.Now.Year + " " + setupInfo.SiteName,
        //        DateFormat = "dd/mm/yyyy",
        //        EmailAddress = setupInfo.Email,
        //        Name = setupInfo.SiteName,
        //        NewUserRole = "Reader",
        //        //SiteTitle = setupInfo.SiteName,
        //        //Tagline = setupInfo.Tagline,
        //        TimeFormat = "hh:mm:ss",
        //        TimeZone = "UTC_6"
        //    };
        //    webSiteService.Save(webSite);
        //}

        public static void CrateNccWebSite(NccDbContext dbContext, WebSiteInfo webSiteInfo)
        {
            var webSiteRepository     = new NccWebSiteRepository(dbContext);
            var webSiteInfoRepository = new NccWebSiteInfoRepository(dbContext);
            var webSiteService        = new NccWebSiteService(webSiteRepository, webSiteInfoRepository);
            var webSite = new NccWebSite()
            {
                Name = webSiteInfo.SiteName,
                AllowRegistration = true,
                DateFormat        = "dd/MM/yyyy",
                TimeFormat        = "hh:mm:ss",
                EmailAddress      = webSiteInfo.Email,
                Language          = webSiteInfo.Language,
                NewUserRole       = "Subscriber",
                TimeZone          = "UTC_6",
                EnableCache       = webSiteInfo.EnableCache
            };

            if (string.IsNullOrEmpty(webSiteInfo.TablePrefix) == false)
            {
                if (webSiteInfo.TablePrefix.EndsWith("_"))
                {
                    webSite.TablePrefix = webSiteInfo.TablePrefix.Trim();
                }
                else
                {
                    webSite.TablePrefix = webSiteInfo.TablePrefix.Trim() + "_";
                }
            }
            else
            {
                webSite.TablePrefix = "";
            }

            webSite.WebSiteInfos = new List <NccWebSiteInfo>();
            foreach (var item in SupportedCultures.Cultures)
            {
                webSite.WebSiteInfos.Add(new NccWebSiteInfo()
                {
                    Language  = item.TwoLetterISOLanguageName,
                    Name      = webSiteInfo.SiteName,
                    SiteTitle = webSiteInfo.SiteName,
                    Tagline   = webSiteInfo.Tagline
                });
            }

            webSiteService.Save(webSite);
        }
Ejemplo n.º 5
0
        public static void CreateWebSite(NccDbContext dbContext, WebSiteInfo setupInfo)
        {
            var webSiteRepository = new NccWebSiteRepository(dbContext);
            var webSiteService    = new NccWebSiteService(webSiteRepository);
            var webSite           = new NccWebSite()
            {
                AllowRegistration = true,
                Copyrights        = "Copyright (c) " + DateTime.Now.Year + " " + setupInfo.SiteName,
                DateFormat        = "dd/mm/yyyy",
                EmailAddress      = setupInfo.Email,
                Name        = setupInfo.SiteName,
                NewUserRole = "Reader",
                SiteTitle   = setupInfo.SiteName,
                Tagline     = setupInfo.Tagline,
                TimeFormat  = "hh:mm:ss",
                TimeZone    = "UTC +6"
            };

            webSiteService.Save(webSite);
        }
Ejemplo n.º 6
0
 public BaseRepository(NccDbContext context)
 {
     Context = context;
     DbSet   = Context.Set <EntityT>();
 }
Ejemplo n.º 7
0
 public NccPostRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 8
0
 public NccUserRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 9
0
 public NeNewsRepository(NccDbContext context) : base(context)
 {
 }
 public NccSettingsRepository(NccDbContext context) : base(context)
 {
 }
 public NccStartupRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 12
0
 public NccScheduleTaskHistoryRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 13
0
 public NccPageDetailsRepository(NccDbContext context) : base(context)
 {
 }
 public SubscriptionUserRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 15
0
 public HelloRepository(NccDbContext context) : base(context)
 {
 }
 public NccPermissionDetailsRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 17
0
 public NccWebSiteRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 18
0
 public NccRoleStore(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 19
0
 public NccNoticeRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 20
0
 public NccModuleRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 21
0
 public NeCategoryRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 22
0
 public NccCategoryDetailsRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 23
0
 public NccTagRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 24
0
        public async Task <ActionResult> CreateAdmin(AdminViewModel viewModel)
        {
            SetupHelper.InitilizeDatabase();

            var optionBuilder = new DbContextOptionsBuilder <NccDbContext>();

            DatabaseEngine dbe = TypeConverter.TryParseDatabaseEnum(SetupHelper.SelectedDatabase);

            switch (dbe)
            {
            case DatabaseEngine.MSSQL:
                optionBuilder.UseSqlServer(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                break;

            case DatabaseEngine.MsSqlLocalStorage:
                break;

            case DatabaseEngine.MySql:
                optionBuilder.UseMySql(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                break;

            case DatabaseEngine.SqLite:
                optionBuilder.UseSqlite(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                break;

            case DatabaseEngine.PgSql:
                break;
            }

            var nccDbConetxt = new NccDbContext(optionBuilder.Options);

            var userStore              = new NccUserStore(nccDbConetxt);
            var identityOptions        = Options.Create(new IdentityOptions());
            var passwordHasher         = new PasswordHasher <NccUser>();
            var userValidatorList      = new List <UserValidator <NccUser> >();
            var passwordValidatorList  = new List <PasswordValidator <NccUser> >();
            var lookupNormalizer       = new UpperInvariantLookupNormalizer();
            var identityErrorDescriber = new IdentityErrorDescriber();
            var logger = _loggerFactory.CreateLogger <UserManager <NccUser> >();

            var userManager = new UserManager <NccUser>(
                userStore,
                identityOptions,
                passwordHasher,
                userValidatorList,
                passwordValidatorList,
                lookupNormalizer,
                identityErrorDescriber,
                GlobalConfig.App.ApplicationServices,
                logger
                );

            var roleStore         = new NccRoleStore(nccDbConetxt);
            var roleValidatorList = new List <RoleValidator <NccRole> >();
            var roleLogger        = _loggerFactory.CreateLogger <RoleManager <NccRole> >();

            var roleManager = new RoleManager <NccRole>(
                roleStore,
                roleValidatorList,
                new UpperInvariantLookupNormalizer(),
                new IdentityErrorDescriber(),
                roleLogger,
                _httpContextAccessor
                );

            var claimsFactory = new UserClaimsPrincipalFactory <NccUser, NccRole>(userManager, roleManager, identityOptions);
            var signInLogger  = _loggerFactory.CreateLogger <SignInManager <NccUser> >();
            var signInManager = new NccSignInManager <NccUser>(userManager, _httpContextAccessor, claimsFactory, identityOptions, signInLogger);

            //nccDbConetxt.Database.Migrate();

            var setupInfo = new WebSiteInfo()
            {
                SiteName         = viewModel.SiteName,
                Tagline          = viewModel.Tagline,
                AdminPassword    = viewModel.AdminPassword,
                AdminUserName    = viewModel.AdminUserName,
                ConnectionString = SetupHelper.ConnectionString,
                Database         = TypeConverter.TryParseDatabaseEnum(SetupHelper.SelectedDatabase),
                Email            = viewModel.Email
            };

            var admin = await SetupHelper.CreateSuperAdminUser(userManager, roleManager, signInManager, setupInfo);

            SetupHelper.RegisterAuthServices();
            SetupHelper.IsAdminCreateComplete = true;
            SetupHelper.SaveSetup();
            SetupHelper.CrateNccWebSite(nccDbConetxt, setupInfo);

            return(Redirect("/Home/SetupSuccess"));
        }
Ejemplo n.º 25
0
        public static async Task SaveBasicData(NccUser nccUser, NccDbContext nccDbConetxt, UserManager <NccUser> userManager, RoleManager <NccRole> roleManager, NccSignInManager <NccUser> signInManager, WebSiteInfo setupInfo)
        {
            string enDemoTitle   = "";
            string enDemoSlug    = "";
            string enDemoContent = "";
            string bnDemoTitle   = "";
            string bnDemoSlug    = "";
            string bnDemoContent = "";

            //var webSiteRepository = new NccWebSiteRepository(nccDbConetxt);
            //var webSiteInfoRepository = new NccWebSiteInfoRepository(nccDbConetxt);
            //var webSiteService = new NccWebSiteService(webSiteRepository, webSiteInfoRepository);

            #region Create a sample page
            var nccPageRepository        = new NccPageRepository(nccDbConetxt);
            var nccPageDetailsRepository = new NccPageDetailsRepository(nccDbConetxt);
            var nccPageService           = new NccPageService(nccPageRepository, nccPageDetailsRepository);

            try
            {
                enDemoTitle   = "Sample Page ";
                enDemoSlug    = "Sample-Page";
                enDemoContent = "This is a sample page.";
                bnDemoTitle   = "নমুনা পৃষ্ঠা ";
                bnDemoSlug    = "নমুনা-পৃষ্ঠা";
                bnDemoContent = "এটি একটি নমুনা পাতা।";

                NccPage page = new NccPage();
                page.Metadata    = "DEMODATA";
                page.PublishDate = DateTime.Now;
                page.PageStatus  = NccPageStatus.Published;
                page.PageType    = NccPageType.Public;
                page.Layout      = "SiteLayout";
                page.CreateBy    = page.ModifyBy = 1;
                page.Name        = enDemoTitle;

                foreach (var item in SupportedCultures.Cultures)
                {
                    NccPageDetails _nccPageDetails = new NccPageDetails();
                    _nccPageDetails.Language = item.TwoLetterISOLanguageName;
                    if (item.TwoLetterISOLanguageName == "en")
                    {
                        _nccPageDetails.Title           = enDemoTitle;
                        _nccPageDetails.Slug            = enDemoSlug;
                        _nccPageDetails.Name            = enDemoSlug;
                        _nccPageDetails.Content         = "<h1 style=\"text-align:center\">" + enDemoTitle + "</h1><p>" + enDemoContent + "</p>";
                        _nccPageDetails.MetaDescription = enDemoTitle + " " + enDemoContent;
                    }
                    else if (item.TwoLetterISOLanguageName == "bn")
                    {
                        _nccPageDetails.Title           = bnDemoTitle;
                        _nccPageDetails.Slug            = bnDemoSlug;
                        _nccPageDetails.Name            = bnDemoSlug;
                        _nccPageDetails.Content         = "<h1 style=\"text-align:center\">" + bnDemoTitle + "</h1><p>" + bnDemoContent + "</p>";
                        _nccPageDetails.MetaDescription = bnDemoTitle + " " + bnDemoContent;
                    }
                    page.PageDetails.Add(_nccPageDetails);
                }
                nccPageService.Save(page);
            }
            catch (Exception ex)
            {
            }
            #endregion

            #region Create a sample category
            var categoryRepository = new NccCategoryRepository(nccDbConetxt);
            var categoryService    = new NccCategoryService(categoryRepository);

            try
            {
                enDemoTitle = "Sample Category ";
                enDemoSlug  = "Sample-Category";
                bnDemoTitle = "নমুনা ক্যাটাগরি ";
                bnDemoSlug  = "নমুনা-ক্যাটাগরি";
                NccCategory item = new NccCategory();
                item.Metadata      = "DEMODATA";
                item.Name          = enDemoTitle;
                item.CategoryImage = "/media/Images/2017/06/image-slider-0.jpg";
                foreach (var lang in SupportedCultures.Cultures)
                {
                    NccCategoryDetails _nccDetails = new NccCategoryDetails();
                    _nccDetails.Language = lang.TwoLetterISOLanguageName;
                    if (lang.TwoLetterISOLanguageName == "en")
                    {
                        _nccDetails.Title = enDemoTitle;
                        _nccDetails.Slug  = enDemoSlug;
                        _nccDetails.Name  = enDemoSlug;
                    }
                    else if (lang.TwoLetterISOLanguageName == "bn")
                    {
                        _nccDetails.Title = bnDemoTitle;
                        _nccDetails.Slug  = bnDemoSlug;
                        _nccDetails.Name  = bnDemoSlug;
                    }
                    item.CategoryDetails.Add(_nccDetails);
                }
                categoryService.Save(item);
            }
            catch (Exception ex) { }
            #endregion
            //var tagRepository = new NccTagRepository(nccDbConetxt);
            //var tagService = new NccTagService(tagRepository);

            #region Create a sample post
            var postRepository        = new NccPostRepository(nccDbConetxt);
            var postDetailsRepository = new NccPostDetailsRepository(nccDbConetxt);
            var postService           = new NccPostService(postRepository, postDetailsRepository);

            try
            {
                enDemoTitle   = "Sample Post ";
                enDemoSlug    = "Sample-Post";
                enDemoContent = "This is a sample post.";
                bnDemoTitle   = "নমুনা পোস্ট ";
                bnDemoSlug    = "নমুনা-পোস্ট";
                bnDemoContent = "এটি একটি নমুনা পোস্ট।";
                var categoryList = categoryService.LoadAll();

                NccPost post = new NccPost();
                post.Metadata     = "DEMODATA";
                post.PublishDate  = DateTime.Now;
                post.PostStatus   = NccPostStatus.Published;
                post.PostType     = NccPostType.Public;
                post.Layout       = "SiteLayout";
                post.CreateBy     = post.ModifyBy = 1;
                post.Name         = enDemoTitle;
                post.AllowComment = true;
                post.ThumImage    = "/media/Images/2017/06/image-slider-2.jpg";
                foreach (var postItem in SupportedCultures.Cultures)
                {
                    NccPostDetails _nccPostDetails = new NccPostDetails();
                    _nccPostDetails.Language = postItem.TwoLetterISOLanguageName;
                    if (postItem.TwoLetterISOLanguageName == "en")
                    {
                        _nccPostDetails.Title           = enDemoTitle;
                        _nccPostDetails.Slug            = enDemoSlug;
                        _nccPostDetails.Name            = enDemoSlug;
                        _nccPostDetails.Content         = "<h1 style=\"text-align:center\">" + enDemoTitle + "</h1><hr />" + enDemoContent;
                        _nccPostDetails.MetaDescription = enDemoTitle + " " + enDemoContent;
                    }
                    else if (postItem.TwoLetterISOLanguageName == "bn")
                    {
                        _nccPostDetails.Title           = bnDemoTitle;
                        _nccPostDetails.Slug            = bnDemoSlug;
                        _nccPostDetails.Name            = bnDemoSlug;
                        _nccPostDetails.Content         = "<h1 style=\"text-align:center\">" + bnDemoTitle + "</h1><hr />" + bnDemoContent;
                        _nccPostDetails.MetaDescription = bnDemoTitle + " " + bnDemoContent;
                    }
                    post.PostDetails.Add(_nccPostDetails);
                }
                postService.Save(post);

                try
                {
                    post            = postService.Get(post.Id, true);
                    post.Categories = new List <NccPostCategory>();
                    var temp = categoryList.FirstOrDefault();
                    if (temp != null)
                    {
                        if (post.Categories.Where(x => x.CategoryId == temp.Id).Count() <= 0)
                        {
                            post.Categories.Add(new NccPostCategory()
                            {
                                Post = post, CategoryId = temp.Id
                            });
                        }
                    }
                    postService.Update(post);
                }
                catch (Exception ex) { }
            }
            catch (Exception ex) { }
            #endregion

            #region Create a sample comment
            var commentsRepository = new NccCommentsRepository(nccDbConetxt);
            var commentsService    = new NccCommentsService(commentsRepository);
            try
            {
                enDemoContent = "This is a sample comment.";
                bnDemoContent = "এটি একটি নমুনা মন্তব্য।";
                NccComment commentItem = new NccComment();
                commentItem.Metadata = "DEMODATA";
                commentItem.Name     = "Sample Comments";
                commentItem.Content  = enDemoContent;
                if (Language == "bn")
                {
                    commentItem.Content = bnDemoContent;
                }
                commentItem.CommentStatus = NccComment.NccCommentStatus.Approved;
                commentItem.Post          = postService.LoadAll().FirstOrDefault();
                commentsService.Save(commentItem);
            }
            catch (Exception ex) { }
            #endregion

            #region Create sample menu
            var menuRepository     = new NccMenuRepository(nccDbConetxt);
            var menuItemRepository = new NccMenuItemRepository(nccDbConetxt);
            var menuService        = new NccMenuService(menuRepository, menuItemRepository);

            try
            {
                NccMenu nccMenu = new NccMenu()
                {
                    Name         = "Main Menu",
                    Position     = "Navigation",
                    MenuOrder    = 1,
                    MenuLanguage = ""
                };
                if (Language == "bn")
                {
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 1,
                        Module         = "",
                        Name           = "হোম",
                        Target         = "_self",
                        Url            = "/"
                    });
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 2,
                        Module         = "",
                        Name           = "নমুনা পৃষ্ঠা",
                        Target         = "_self",
                        Url            = "/নমুনা-পৃষ্ঠা"
                    });
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 3,
                        Module         = "",
                        Name           = "ব্লগ পোস্ট",
                        Target         = "_self",
                        Url            = "/Post"
                    });
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 4,
                        Module         = "",
                        Name           = "ব্লগ বিভাগ",
                        Target         = "_self",
                        Url            = "/Category"
                    });
                }
                else
                {
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 1,
                        Module         = "",
                        Name           = "Home",
                        Target         = "_self",
                        Url            = "/"
                    });
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 2,
                        Module         = "",
                        Name           = "Sample Page",
                        Target         = "_self",
                        Url            = "/Sample-Page"
                    });
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 3,
                        Module         = "",
                        Name           = "Blog Posts",
                        Target         = "_self",
                        Url            = "/Post"
                    });
                    nccMenu.MenuItems.Add(new NccMenuItem()
                    {
                        Action     = "",
                        Controller = "",
                        Data       = "",
                        //Id = item.Id,
                        MenuActionType = NccMenuItem.ActionType.Url,
                        MenuOrder      = 4,
                        Module         = "",
                        Name           = "Blog Categories",
                        Target         = "_self",
                        Url            = "/Category"
                    });
                }

                menuService.Save(nccMenu);
            }
            catch (Exception ex) { }
            #endregion

            #region Create sample widget
            //var currentWebsite = nccWebSiteService.LoadAll().FirstOrDefault();
            //var nccWebSiteWidget = new NccWebSiteWidget()
            //{
            //    WebSite = currentWebsite,
            //    WidgetConfigJson = "",
            //    ModuleId = "NetCoreCMS.Core.Modules.Cms",
            //    WidgetId = "NetCoreCms.Modules.Cms.CmsSearch",
            //    ThemeId = "com.NetCoreCMS.themes.NccSeventeen",
            //    LayoutName = "SiteLayout",
            //    Zone = "RightSidebar",
            //    WidgetOrder = 1,
            //    WidgetData = "",
            //};
            //nccWebSiteWidgetService.Save(nccWebSiteWidget);
            #endregion
        }
Ejemplo n.º 26
0
 public NccImageSliderRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 27
0
 public NccMenuItemRepository(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 28
0
        public async Task <ActionResult> CreateAdmin(AdminViewModel viewModel)
        {
            if (viewModel.AdminPassword != viewModel.ConfirmPassword)
            {
                ViewBag.Languages = new SelectList(SupportedCultures.Cultures.Select(x => new { Value = x.TwoLetterISOLanguageName, Text = x.DisplayName }).ToList(), "Value", "Text");
                ModelState.AddModelError("ConfirmPassword", "Password does not match");
                return(View(viewModel));
            }

            SetupHelper.InitilizeDatabase();

            if (SetupHelper.IsDbCreateComplete == true && SetupHelper.IsAdminCreateComplete == false)
            {
                if (!ModelState.IsValid)
                {
                    ViewBag.Languages = new SelectList(SupportedCultures.Cultures.Select(x => new { Value = x.TwoLetterISOLanguageName, Text = x.DisplayName }).ToList(), "Value", "Text");
                    return(View(viewModel));
                }

                var optionBuilder = new DbContextOptionsBuilder <NccDbContext>();

                SupportedDatabases supportedDatabases = TypeConverter.TryParseDatabaseEnum(SetupHelper.SelectedDatabase);

                switch (supportedDatabases)
                {
                case SupportedDatabases.MSSQL:
                    optionBuilder.UseSqlServer(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                    break;

                case SupportedDatabases.MsSqlLocalStorage:
                    break;

                case SupportedDatabases.MySql:
                    optionBuilder.UseMySql(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                    break;

                case SupportedDatabases.SqLite:
                    optionBuilder.UseSqlite(SetupHelper.ConnectionString, opts => opts.MigrationsAssembly("NetCoreCMS.Framework"));
                    break;

                case SupportedDatabases.PgSql:
                    break;
                }

                var nccDbConetxt = new NccDbContext(optionBuilder.Options);

                var userStore              = new NccUserStore(nccDbConetxt);
                var identityOptions        = Options.Create(new IdentityOptions());
                var passwordHasher         = new PasswordHasher <NccUser>();
                var userValidatorList      = new List <UserValidator <NccUser> >();
                var passwordValidatorList  = new List <PasswordValidator <NccUser> >();
                var lookupNormalizer       = new UpperInvariantLookupNormalizer();
                var identityErrorDescriber = new IdentityErrorDescriber();
                var logger     = _loggerFactory.CreateLogger <UserManager <NccUser> >();
                var authOption = new AuthenticationOptions();
                var options    = Options.Create <AuthenticationOptions>(authOption);
                var scheme     = new AuthenticationSchemeProvider(options);

                var userManager = new UserManager <NccUser>(
                    userStore,
                    identityOptions,
                    passwordHasher,
                    userValidatorList,
                    passwordValidatorList,
                    lookupNormalizer,
                    identityErrorDescriber,
                    GlobalContext.App.ApplicationServices,
                    logger
                    );

                var roleStore         = new NccRoleStore(nccDbConetxt);
                var roleValidatorList = new List <RoleValidator <NccRole> >();
                var roleLogger        = _loggerFactory.CreateLogger <RoleManager <NccRole> >();

                var roleManager = new RoleManager <NccRole>(
                    roleStore,
                    roleValidatorList,
                    new UpperInvariantLookupNormalizer(),
                    new IdentityErrorDescriber(),
                    roleLogger
                    );

                var claimsFactory = new UserClaimsPrincipalFactory <NccUser, NccRole>(userManager, roleManager, identityOptions);
                var signInLogger  = _loggerFactory.CreateLogger <SignInManager <NccUser> >();
                var signInManager = new NccSignInManager <NccUser>(userManager, _httpContextAccessor, claimsFactory, identityOptions, signInLogger, scheme);

                //nccDbConetxt.Database.Migrate();

                var setupInfo = new WebSiteInfo()
                {
                    SiteName         = viewModel.SiteName,
                    Tagline          = viewModel.Tagline,
                    AdminPassword    = viewModel.AdminPassword,
                    AdminUserName    = viewModel.AdminUserName,
                    ConnectionString = SetupHelper.ConnectionString,
                    Database         = TypeConverter.TryParseDatabaseEnum(SetupHelper.SelectedDatabase),
                    Email            = viewModel.Email,
                    Language         = viewModel.Language,
                    TablePrefix      = viewModel.TablePrefix
                };

                //SetupHelper.RegisterAuthServices(supportedDatabases);
                var admin = await SetupHelper.CreateSuperAdminUser(nccDbConetxt, userManager, roleManager, signInManager, setupInfo);

                if (admin != null)
                {
                    SetupHelper.IsAdminCreateComplete = true;
                    SetupHelper.Language = viewModel.Language;
                    SetupHelper.SaveSetup();
                    SetupHelper.CrateNccWebSite(nccDbConetxt, setupInfo);

                    await SetupHelper.SaveBasicData(admin, nccDbConetxt, userManager, roleManager, signInManager, setupInfo);

                    return(Redirect("/Home/SetupSuccess"));
                }
                else
                {
                    TempData["ErrorMessage"] = "Could not create Admin user and Roles.";
                    return(Redirect("/Home/Error"));
                }
            }

            TempData["ErrorMessage"] = "Setup already completed.";
            return(Redirect("/Home/Error"));
        }
Ejemplo n.º 29
0
 public NccUserStore(NccDbContext context) : base(context)
 {
 }
Ejemplo n.º 30
0
 public NccCommentsRepository(NccDbContext context) : base(context)
 {
 }