Пример #1
0
        public static object GetSettingValue(Enums.EnumGeneralSetting setting)
        {
            DAL.ServiceContext db = new DAL.ServiceContext();
            var dbsetting         = db.GeneralSettings.FirstOrDefault(ln => ln.GeneralSetting == setting);

            if (dbsetting != null)
            {
                switch (dbsetting.Type)
                {
                case Enums.EnumSettingType.Bool:
                    return(bool.Parse(dbsetting.Value));

                case Enums.EnumSettingType.Decimal:
                    return(decimal.Parse(dbsetting.Value, System.Globalization.CultureInfo.CreateSpecificCulture("en-US")));

                case Enums.EnumSettingType.Float:
                    return(float.Parse(dbsetting.Value));

                case Enums.EnumSettingType.Int:
                    return(int.Parse(dbsetting.Value));

                case Enums.EnumSettingType.String:
                    return(dbsetting.Value.ToString());

                default:
                    return(null);
                }
            }
            throw new Exceptions.SettingNotFoundException("Setting not found: " + setting.ToString());
        }
Пример #2
0
        public GeneralSettingsViewModel Update(int Id, Enums.EnumGeneralSetting Name, Enums.EnumSettingType Type, string Value)
        {
            var dbobj = db.GeneralSettings.FirstOrDefault(ln => ln.Id == Id);

            dbobj.GeneralSetting = Name;
            dbobj.Type           = Type;
            dbobj.Value          = Value;
            db.SaveChanges();
            return(dbobj.ToGeneralSettingsViewModel());
        }
Пример #3
0
        public GeneralSettingsViewModel Create(Enums.EnumGeneralSetting Name, Enums.EnumSettingType Type, string Value)
        {
            var dbobj = db.GeneralSettings.Add(new Models.GeneralSettingsModel()
            {
                GeneralSetting = Name,
                Type           = Type,
                Value          = Value
            });

            db.SaveChanges();
            return(dbobj.ToGeneralSettingsViewModel());
        }