Example #1
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 == SioEnums.SioContentStatus.Schedule)
                    {
                        DateTime dtPublish = DateTime.UtcNow;
                        if (model.PublishedDateTime.HasValue)
                        {
                            dtPublish = model.PublishedDateTime.Value;
                        }
                        SioService.SetConfig(SioConstants.ConfigurationKeyword.NextSyncContent, dtPublish);
                        SioService.SaveSettings();
                        SioService.Reload();
                    }
                }
                return(result);
            }
            return(new RepositoryResponse <UpdateViewModel>()
            {
                Status = 501
            });
        }
Example #2
0
        DateTime?PublishArticles()
        {
            var nextSync = SioService.GetConfig <DateTime?>(SioConstants.ConfigurationKeyword.NextSyncContent);

            if (nextSync.HasValue && nextSync.Value <= DateTime.UtcNow)
            {
                var publishedArticles = ReadListItemViewModel.Repository.GetModelListBy(
                    a => a.Status == (int)SioContentStatus.Schedule &&
                    (!a.PublishedDateTime.HasValue || a.PublishedDateTime.Value <= DateTime.UtcNow)
                    );
                publishedArticles.Data.ForEach(a => a.Status = SioContentStatus.Published);
                base.SaveList(publishedArticles.Data, false);
                var next = ReadListItemViewModel.Repository.Min(a => a.Type == (int)SioContentStatus.Schedule,
                                                                a => a.PublishedDateTime);
                nextSync = next.Data;
                SioService.SetConfig(SioConstants.ConfigurationKeyword.NextSyncContent, nextSync);
                SioService.SaveSettings();
                SioService.Reload();
                return(nextSync);
            }
            else
            {
                return(nextSync);
            }
        }
Example #3
0
        public async Task <RepositoryResponse <SioConfiguration> > DeleteAsync(string keyword)
        {
            var result = await base.DeleteAsync <UpdateViewModel>(
                model => model.Keyword == keyword && model.Specificulture == _lang, true);

            if (result.IsSucceed)
            {
                SioService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow);
            }
            return(result);
        }
Example #4
0
        public async Task <RepositoryResponse <SioCulture> > DeleteAsync(int id)
        {
            var result = await base.DeleteAsync <UpdateViewModel>(
                model => model.Id == id, true);

            if (result.IsSucceed)
            {
                SioService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow);
            }
            return(result);
        }
Example #5
0
        public async Task <RepositoryResponse <UpdateViewModel> > Save([FromBody] UpdateViewModel model)
        {
            var result = await base.SaveAsync <UpdateViewModel>(model, true);

            if (result.IsSucceed)
            {
                SioService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow);
                SioService.LoadFromDatabase();
                SioService.SaveSettings();
            }
            return(result);
        }
Example #6
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();
                FileRepository.Instance.SaveFile(settings);
                SioService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow);
            }
            return(new RepositoryResponse <JObject>()
            {
                IsSucceed = model != null, Data = model
            });
        }
Example #7
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)
                {
                    SioService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow);
                }
                return(result);
            }
            return(new RepositoryResponse <UpdateViewModel>()
            {
                Status = 501
            });
        }
Example #8
0
        private async Task <RepositoryResponse <bool> > InitCmsAsync(InitCmsViewModel model)
        {
            var result = new RepositoryResponse <bool>();

            SioService.SetConnectionString(SioConstants.CONST_CMS_CONNECTION, model.ConnectionString);
            SioService.SetConnectionString(SioConstants.CONST_MESSENGER_CONNECTION, model.ConnectionString);
            SioService.SetConnectionString(SioConstants.CONST_ACCOUNT_CONNECTION, model.ConnectionString);
            SioService.SetConfig(SioConstants.CONST_SETTING_IS_MYSQL, model.IsMysql);
            SioService.SetConfig(SioConstants.CONST_SETTING_DATABASE_PROVIDER, model.DatabaseProvider);
            SioService.SetConfig(SioConstants.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;
                SioService.LoadFromDatabase();
                SioService.SetConfig <bool>("IsInit", true);
                SioService.SetConfig <string>("DefaultCulture", model.Culture.Specificulture);
                SioService.SaveSettings();
                SioService.Reload();
            }
            else
            {
                // if cannot init cms
                //  => reload from default settings
                //  => save to appSettings
                SioService.Reload();
                SioService.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);
        }
        private async Task <RepositoryResponse <bool> > InitCmsAsync(InitCmsViewModel model)
        {
            var result = new RepositoryResponse <bool>();

            SioService.SetConnectionString(SioConstants.CONST_CMS_CONNECTION, model.ConnectionString);
            SioService.SetConnectionString(SioConstants.CONST_MESSENGER_CONNECTION, model.ConnectionString);
            SioService.SetConnectionString(SioConstants.CONST_ACCOUNT_CONNECTION, model.ConnectionString);
            SioService.SetConfig(SioConstants.CONST_SETTING_IS_SQLITE, model.IsSqlite);
            SioService.SetConfig(SioConstants.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;
                SioService.LoadFromDatabase();
                SioService.SetConfig <bool>("IsInit", true);
                SioService.SetConfig <string>("DefaultCulture", model.Culture.Specificulture);
                SioService.Save();
                SioService.Reload();
            }
            else
            {
                SioService.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);
        }