Exemple #1
0
        /// <summary>
        /// Set một giá trị theo key và mô tả
        /// </summary>
        /// <param name="key">Khóa</param>
        /// <param name="value">Giá trị</param>
        /// <returns>Nếu đã tồn tại thì sẽ update</returns>
        private bool SetStringByKey(string key, string value)
        {
            using SystemDbContext dbContext = new SystemDbContext(new DbContextOptionsBuilder <SystemDbContext>().UseSqlServer(_connectionString).Options);
            SystemValue systemKeyValue = dbContext.SystemValues.FirstOrDefault(q => q.Key == key);

            if (systemKeyValue != null)
            {
                systemKeyValue.Value = value;
            }
            else
            {
                dbContext.SystemValues.Add(new SystemValue()
                {
                    Key = key, Value = value
                });
            }
            return(dbContext.SaveChanges() > 0);
        }
Exemple #2
0
        /// <summary>
        /// Lấy nội dung file thiết lập nếu chưa có thì tạo theo string mặc định chuyền vào
        /// </summary>
        /// <param name="settingJsonStringDefault">string mặc định</param>
        /// <param name="key">Đường dẫn đến file setting</param>
        /// <param name="description">Mô tả cho khóa dữ liệu</param>
        /// <returns>nội dung file setting</returns>
        private string GetSettingsOfCreateIfNotExist(string settingJsonStringDefault, string key, string description = "")
        {
            using SystemDbContext dbContext = new SystemDbContext(new DbContextOptionsBuilder <SystemDbContext>().UseSqlServer(_connectionString).Options);
            SystemValue systemKeyValue = dbContext.SystemValues.FirstOrDefault(q => q.Key == key);

            if (systemKeyValue != null)
            {
                return(systemKeyValue.Value);
            }

            systemKeyValue = new SystemValue()
            {
                Key = key, Value = settingJsonStringDefault, Description = description
            };
            dbContext.SystemValues.Add(systemKeyValue);
            dbContext.SaveChanges();
            return(settingJsonStringDefault);
        }
Exemple #3
0
        /// <summary>
        /// add system data to service container, Ensure call <see cref="SystemDataProtection"/>.InitializeFileSystemProtecter fisrt to setup a data protecter
        /// </summary>
        /// <param name="services">Service container</param>
        /// <param name="dbConnection">connection string to db</param>
        /// <param name="contentRootPath">root file content and upload folder of web hosting</param>
        public static void AddSystemDataProvider(this IServiceCollection services, string dbConnection, string contentRootPath)
        {
            using var systemDbContext = new SystemDbContext(new DbContextOptionsBuilder <SystemDbContext>().UseSqlServer(dbConnection).Options);
            systemDbContext.Database.Migrate();

            DbSetting dbSetting = new DbSetting(dbConnection, contentRootPath);

            services.AddSingleton <ISystemSettings>(dbSetting);

            services.AddTransient <IActivityLogData, ActivityLogData>();
            services.AddTransient <ICmsMenuData, CmsMenuData>();
            services.AddTransient <ICurrencyData, CurrencyData>();
            services.AddTransient <IFileResourceData, FileResourceData>();
            services.AddTransient <IFileResourceMappingData, FileResourceMappingData>();
            services.AddTransient <ILanguageData, LanguageData>();
            services.AddTransient <ILanguageResourceData, LanguageResourceData>();
            services.AddTransient <IObjectLocalizedData, ObjectLocalizedData>();
            services.AddTransient <IScheduleTaskData, ScheduleTaskData>();
            services.AddTransient <ISystemValueData, SystemValueData>();
        }
Exemple #4
0
 public ScheduleTaskData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
Exemple #5
0
 public CmsMenuData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
 public ObjectLocalizedData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
Exemple #7
0
 public ActivityLogData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
Exemple #8
0
 public SystemValueData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
Exemple #9
0
 public FileResourceData(ISystemSettings systemSettings, SystemDbContext systemDbContext) : base(systemDbContext)
 {
     _systemSettings = systemSettings;
 }
Exemple #10
0
 public LanguageData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
Exemple #11
0
 public CurrencyData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }
 public FileResourceMappingData(SystemDbContext systemDbContext) : base(systemDbContext)
 {
 }