Exemplo n.º 1
0
        DateTime?PublishPosts()
        {
            var nextSync = MixService.GetConfig <DateTime?>(MixConstants.ConfigurationKeyword.NextSyncContent);

            if (nextSync.HasValue && nextSync.Value <= DateTime.UtcNow)
            {
                var publishedPosts = ReadListItemViewModel.Repository.GetModelListBy(
                    a => a.Status == (int)MixContentStatus.Schedule &&
                    (!a.PublishedDateTime.HasValue || a.PublishedDateTime.Value <= DateTime.UtcNow)
                    );
                publishedPosts.Data.ForEach(a => a.Status = MixContentStatus.Published);
                base.SaveList(publishedPosts.Data, false);
                var next = ReadListItemViewModel.Repository.Min(a => a.Type == (int)MixContentStatus.Schedule,
                                                                a => a.PublishedDateTime);
                nextSync = next.Data;
                MixService.SetConfig(MixConstants.ConfigurationKeyword.NextSyncContent, nextSync);
                MixService.SaveSettings();
                MixService.Reload();
                return(nextSync);
            }
            else
            {
                return(nextSync);
            }
        }
Exemplo n.º 2
0
        private async Task <RepositoryResponse <bool> > InitStep1Async(InitCmsViewModel model)
        {
            MixService.SetConnectionString(MixConstants.CONST_CMS_CONNECTION, model.ConnectionString);
            MixService.SetConnectionString(MixConstants.CONST_MESSENGER_CONNECTION, model.ConnectionString);
            MixService.SetConnectionString(MixConstants.CONST_ACCOUNT_CONNECTION, model.ConnectionString);
            MixService.SetConfig(MixConstants.CONST_SETTING_DATABASE_PROVIDER, model.DatabaseProvider.ToString());
            MixService.SetConfig(MixConstants.CONST_SETTING_LANGUAGE, model.Culture.Specificulture);
            MixService.SaveSettings();
            var result = await InitCmsService.InitCms(model.SiteName, model.Culture);

            if (result.IsSucceed)
            {
                await InitRolesAsync();

                result.IsSucceed = true;
                MixService.LoadFromDatabase();
                MixService.SetConfig <string>("DefaultCulture", model.Culture.Specificulture);
                MixService.SetConfig("InitStatus", 1);
                MixService.SaveSettings();
                //MixService.Reload();
            }
            else
            {
                // if cannot init cms
                //  => reload from default settings
                //  => save to appSettings
                MixService.Reload();
                MixService.SaveSettings();
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <RepositoryResponse <UpdateViewModel> > Save([FromBody] UpdateViewModel model)
        {
            if (model != null)
            {
                model.CreatedBy = User.Claims.FirstOrDefault(c => c.Type == "Username")?.Value;
                var result = await base.SaveAsync <UpdateViewModel>(model, true);

                if (result.IsSucceed)
                {
                    if (model.Status == MixEnums.MixContentStatus.Schedule)
                    {
                        DateTime dtPublish = DateTime.UtcNow;
                        if (model.PublishedDateTime.HasValue)
                        {
                            dtPublish = model.PublishedDateTime.Value;
                        }
                        MixService.SetConfig(MixConstants.ConfigurationKeyword.NextSyncContent, dtPublish);
                        MixService.SaveSettings();
                        MixService.Reload();
                    }
                }
                return(result);
            }
            return(new RepositoryResponse <UpdateViewModel>()
            {
                Status = 501
            });
        }
Exemplo n.º 4
0
        public async Task <RepositoryResponse <bool> > InitLanguages([FromBody] List <MixLanguage> model)
        {
            if (model != null)
            {
                var result = new RepositoryResponse <bool>();
                if (MixService.GetConfig <int>("InitStatus") == 3)
                {
                    string         culture = MixService.GetConfig <string>("DefaultCulture");
                    InitCmsService sv      = new InitCmsService();
                    result = await sv.InitLanguagesAsync(culture, model);

                    if (result.IsSucceed)
                    {
                        MixService.LoadFromDatabase();
                        MixService.SetConfig("InitStatus", 4);
                        MixService.SetConfig("IsInit", true);
                        MixService.SaveSettings();
                        _ = Services.CacheService.RemoveCacheAsync();
                        MixService.Reload();
                    }
                }
                return(result);
            }
            return(new RepositoryResponse <bool>());
        }
Exemplo n.º 5
0
        [RequestFormSizeLimit(valueCountLimit: 214748364)] // 200Mb
        public async Task <RepositoryResponse <Cms.Lib.ViewModels.MixThemes.InitViewModel> > Save([FromForm] string model, [FromForm] IFormFile assets, [FromForm] IFormFile theme)
        {
            var json = JObject.Parse(model);
            var data = json.ToObject <Lib.ViewModels.MixThemes.InitViewModel>();

            if (theme != null)
            {
                string importFolder = $"Imports/Themes/{DateTime.UtcNow.ToString("dd-MM-yyyy")}/{data.Name}";
                FileRepository.Instance.SaveWebFile(theme, theme.FileName, importFolder);
                data.TemplateAsset = new Lib.ViewModels.FileViewModel(theme, importFolder);
            }
            else
            {
                if (data.IsCreateDefault)
                {
                    data.TemplateAsset = new Lib.ViewModels.FileViewModel()
                    {
                        Filename   = "default",
                        Extension  = ".zip",
                        FileFolder = "Imports/Themes"
                    };
                }
                else
                {
                    data.TemplateAsset = new Lib.ViewModels.FileViewModel()
                    {
                        Filename   = "default_blank",
                        Extension  = ".zip",
                        FileFolder = "Imports/Themes"
                    };
                }
            }

            if (data != null)
            {
                string culture = MixService.GetConfig <string>("DefaultCulture");
                data.Title          = MixService.GetConfig <string>("SiteName", culture);
                data.Name           = SeoHelper.GetSEOString(data.Title);
                data.CreatedBy      = User.Claims.FirstOrDefault(c => c.Type == "Username")?.Value ?? "Init";
                data.Specificulture = _lang;
                var result = await data.SaveModelAsync(true);

                if (result.IsSucceed)
                {
                    // MixService.SetConfig<string>("SiteName", _lang, data.Title);
                    MixService.LoadFromDatabase();
                    MixService.SetConfig("InitStatus", 3);
                    MixService.SetConfig("IsInit", false);
                    MixService.SaveSettings();
                    _ = MixCacheService.RemoveCacheAsync();
                    MixService.Reload();
                }
                return(result);
            }
            return(new RepositoryResponse <Lib.ViewModels.MixThemes.InitViewModel>()
            {
                Status = 501
            });
        }
Exemplo n.º 6
0
        public static async Task <RepositoryResponse <InitViewModel> > InitTheme(string model, string userName, string culture, IFormFile assets, IFormFile theme)
        {
            var json = JObject.Parse(model);
            var data = json.ToObject <InitViewModel>();

            if (data != null)
            {
                data.CreatedBy = userName;
                data.Status    = MixContentStatus.Published;
                string importFolder = $"{MixFolders.ImportFolder}/" +
                                      $"{DateTime.UtcNow.ToString("dd-MM-yyyy")}";
                if (theme != null)
                {
                    MixFileRepository.Instance.SaveWebFile(theme, $"{importFolder}");
                    data.TemplateAsset = new FileViewModel(theme, importFolder);
                }
                else
                {
                    if (data.IsCreateDefault)
                    {
                        data.TemplateAsset = new FileViewModel()
                        {
                            Filename   = "default",
                            Extension  = MixFileExtensions.Zip,
                            FileFolder = MixFolders.ImportFolder
                        };
                    }
                    else
                    {
                        data.TemplateAsset = new FileViewModel()
                        {
                            Filename   = "default_blank",
                            Extension  = MixFileExtensions.Zip,
                            FileFolder = MixFolders.ImportFolder
                        };
                    }
                }

                data.Title          = MixService.GetConfig <string>(MixAppSettingKeywords.SiteName, culture);
                data.Name           = SeoHelper.GetSEOString(data.Title);
                data.Specificulture = culture;
                var result = await data.SaveModelAsync(true);

                if (result.IsSucceed)
                {
                    // MixService.SetConfig<string>(MixAppSettingKeywords.SiteName, _lang, data.Title);
                    MixService.LoadFromDatabase();
                    MixService.SetConfig("InitStatus", 3);
                    MixService.SetConfig(MixAppSettingKeywords.IsInit, false);
                    MixService.SaveSettings();
                    _ = Mix.Services.MixCacheService.RemoveCacheAsync();
                    MixService.Reload();
                }
                return(result);
            }
            return(new RepositoryResponse <InitViewModel>());
        }
Exemplo n.º 7
0
        public async Task <RepositoryResponse <AccessTokenViewModel> > InitSuperAdmin([FromBody] MixRegisterViewModel model)
        {
            RepositoryResponse <AccessTokenViewModel> result = new RepositoryResponse <AccessTokenViewModel>();

            if (ModelState.IsValid)
            {
                if (_userManager.Users.Count() == 0)
                {
                    var user = new ApplicationUser
                    {
                        UserName  = model.Username,
                        Email     = model.Email,
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        Avatar    = model.Avatar ?? MixService.GetConfig <string>("DefaultAvatar"),
                        JoinDate  = DateTime.UtcNow
                    };
                    var createResult = await _userManager.CreateAsync(user, password : model.Password).ConfigureAwait(false);

                    if (createResult.Succeeded)
                    {
                        user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);

                        await _userManager.AddToRoleAsync(user, "SuperAdmin");

                        var token = await _idHelper.GenerateAccessTokenAsync(user, true);

                        if (token != null)
                        {
                            result.IsSucceed = true;
                            MixService.LoadFromDatabase();
                            MixService.SetConfig("InitStatus", 2);
                            MixService.SaveSettings();
                            MixService.Reload();
                            result.Data = token;
                            return(result);
                        }
                        else
                        {
                            return(result);
                        }
                    }
                    else
                    {
                        foreach (var error in createResult.Errors)
                        {
                            result.Errors.Add(error.Description);
                        }
                        return(result);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        public static async Task <RepositoryResponse <InitViewModel> > InitTheme(string model, string culture, IFormFile assets, IFormFile theme)
        {
            var json = JObject.Parse(model);
            var data = json.ToObject <Lib.ViewModels.MixThemes.InitViewModel>();

            if (data != null)
            {
                string importFolder = $"Imports/Themes/{DateTime.UtcNow.ToString("dd-MM-yyyy")}/{data.Name}";
                if (theme != null)
                {
                    Repositories.FileRepository.Instance.SaveWebFile(theme, theme.FileName, importFolder);
                    data.TemplateAsset = new Lib.ViewModels.FileViewModel(theme, importFolder);
                }
                else
                {
                    if (data.IsCreateDefault)
                    {
                        data.TemplateAsset = new Lib.ViewModels.FileViewModel()
                        {
                            Filename   = "default",
                            Extension  = ".zip",
                            FileFolder = "Imports/Themes"
                        };
                    }
                    else
                    {
                        data.TemplateAsset = new Lib.ViewModels.FileViewModel()
                        {
                            Filename   = "default_blank",
                            Extension  = ".zip",
                            FileFolder = "Imports/Themes"
                        };
                    }
                }

                data.Title          = MixService.GetConfig <string>("SiteName", culture);
                data.Name           = SeoHelper.GetSEOString(data.Title);
                data.Specificulture = culture;
                var result = await data.SaveModelAsync(true);

                if (result.IsSucceed)
                {
                    // MixService.SetConfig<string>("SiteName", _lang, data.Title);
                    MixService.LoadFromDatabase();
                    MixService.SetConfig("InitStatus", 3);
                    MixService.SetConfig("IsInit", false);
                    MixService.SaveSettings();
                    _ = Mix.Services.CacheService.RemoveCacheAsync();
                    MixService.Reload();
                }
                return(result);
            }
            return(new RepositoryResponse <InitViewModel>());
        }
Exemplo n.º 9
0
        public async Task <ActionResult <bool> > Active([FromBody] Lib.ViewModels.MixThemes.UpdateViewModel model)
        {
            model.IsActived = true;
            var result = await Cms.Lib.ViewModels.MixThemes.Helper.ActivedThemeAsync(model.Id, model.Name, model.Specificulture);

            if (result.IsSucceed)
            {
                // MixService.SetConfig<string>(MixAppSettingKeywords.SiteName, _lang, data.Title);
                MixService.LoadFromDatabase();
                MixService.SetConfig("InitStatus", 3);
                MixService.SetConfig(MixAppSettingKeywords.IsInit, false);
                MixService.SaveSettings();
                _ = Mix.Services.MixCacheService.RemoveCacheAsync();
                MixService.Reload();
            }
            return(Ok(result));
        }
Exemplo n.º 10
0
        private async Task <RepositoryResponse <bool> > InitCmsAsync(InitCmsViewModel model)
        {
            var result = new RepositoryResponse <bool>();

            MixService.SetConnectionString(MixConstants.CONST_CMS_CONNECTION, model.ConnectionString);
            MixService.SetConnectionString(MixConstants.CONST_MESSENGER_CONNECTION, model.ConnectionString);
            MixService.SetConnectionString(MixConstants.CONST_ACCOUNT_CONNECTION, model.ConnectionString);
            MixService.SetConfig(MixConstants.CONST_SETTING_IS_MYSQL, model.IsMysql);
            MixService.SetConfig(MixConstants.CONST_SETTING_DATABASE_PROVIDER, model.DatabaseProvider);
            MixService.SetConfig(MixConstants.CONST_SETTING_LANGUAGE, model.Culture.Specificulture);

            InitCmsService sv         = new InitCmsService();
            var            initResult = await sv.InitCms(model.SiteName, model.Culture);

            if (initResult.IsSucceed)
            {
                await InitRolesAsync();

                result.IsSucceed = true;
                MixService.LoadFromDatabase();
                MixService.SetConfig <bool>("IsInit", true);
                MixService.SetConfig <string>("DefaultCulture", model.Culture.Specificulture);
                MixService.SaveSettings();
                MixService.Reload();
            }
            else
            {
                // if cannot init cms
                //  => reload from default settings
                //  => save to appSettings
                MixService.Reload();
                MixService.SaveSettings();
                if (initResult.Exception != null)
                {
                    result.Errors.Add(initResult.Exception.Message);
                    result.Exception = initResult.Exception;
                }
                foreach (var item in initResult.Errors)
                {
                    result.Errors.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 11
0
        public RepositoryResponse <JObject> SaveAppSettings([FromBody] JObject model)
        {
            var settings = FileRepository.Instance.GetFile("appsettings", ".json", string.Empty, true, "{}");

            if (model != null)
            {
                settings.Content = model.ToString();
                if (FileRepository.Instance.SaveFile(settings))
                {
                    MixService.Reload();
                    if (!MixService.GetConfig <bool>("IsCache"))
                    {
                        MixCacheService.RemoveCacheAsync();
                    }
                }
                MixService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow);
            }
            return(new RepositoryResponse <JObject>()
            {
                IsSucceed = model != null, Data = model
            });
        }
Exemplo n.º 12
0
        private async Task <RepositoryResponse <bool> > InitCmsAsync(InitCmsViewModel model)
        {
            var result = new RepositoryResponse <bool>();

            MixService.SetConnectionString(MixConstants.CONST_CMS_CONNECTION, model.ConnectionString);
            MixService.SetConnectionString(MixConstants.CONST_MESSENGER_CONNECTION, model.ConnectionString);
            MixService.SetConnectionString(MixConstants.CONST_ACCOUNT_CONNECTION, model.ConnectionString);
            MixService.SetConfig(MixConstants.CONST_SETTING_IS_SQLITE, model.IsSqlite);
            MixService.SetConfig(MixConstants.CONST_SETTING_LANGUAGE, model.Culture.Specificulture);

            InitCmsService sv         = new InitCmsService();
            var            initResult = await sv.InitCms(model.Culture);

            if (initResult.IsSucceed)
            {
                await InitRolesAsync();

                result.IsSucceed = true;
                MixService.LoadFromDatabase();
                MixService.SetConfig <bool>("IsInit", true);
                MixService.SetConfig <string>("DefaultCulture", model.Culture.Specificulture);
                MixService.Save();
                MixService.Reload();
            }
            else
            {
                MixService.Reload();
                if (initResult.Exception != null)
                {
                    result.Errors.Add(initResult.Exception.Message);
                    result.Exception = initResult.Exception;
                }
                foreach (var item in initResult.Errors)
                {
                    result.Errors.Add(item);
                }
            }
            return(result);
        }