示例#1
0
        public ShoppingSystemSettingModel GetShoppingSystemSettingModel()
        {
            var shoppingSystemSettingModel = new ShoppingSystemSettingModel();
            var pr   = new PropertyReflector();
            var dict = shoppingSystemSettingModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                       .ToDictionary(prop => prop.Name, prop => prop?.GetValue(shoppingSystemSettingModel, null)?.ToString() ?? "");
            var keyValues = _keyValues.Where(x => dict.Keys.Contains(x.Key)).ToList();

            if (keyValues.Any())
            {
                //keyValues.ForEach(x => x.Value = dict[x.Key]);
                foreach (var keyValue in keyValues)
                {
                    pr.SetValue(shoppingSystemSettingModel, keyValue.Key, keyValue.Value);
                }
            }
            return(shoppingSystemSettingModel);
        }
示例#2
0
        public bool SaveShoppingSystemSettingModel(ShoppingSystemSettingModel shoppingSystemSettingModel)
        {
            var dict = shoppingSystemSettingModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                       .ToDictionary(prop => prop.Name, prop => prop?.GetValue(shoppingSystemSettingModel, null)?.ToString() ?? "");
            var keyValues = _keyValues.Where(x => dict.Keys.Contains(x.Key)).ToList();

            if (keyValues.Any())
            {
                keyValues.ForEach(x => x.Value = dict[x.Key]);
            }
            else
            {
                foreach (var item in dict)
                {
                    _keyValues.Add(new KeyValue {
                        Key = item.Key, Value = item.Value
                    });
                }
                //_uow.SaveChanges();
            }
            return(_uow.SaveChanges() != 0);
        }