Ejemplo n.º 1
0
        public HttpResponseMessage Edit(List <SettingModel> model)
        {
            /*if (string.IsNullOrEmpty(model.Value)||string.IsNullOrEmpty(model.Value))
             * {
             *  return PageHelper.toJson(PageHelper.ReturnValue(false,"数据不允许为空!"));
             * }
             * var createNew = false;
             * var setting = _settingService.GetSettingById(model.Id) ?? _settingService.GetSettingByKey(model.Key);
             * if (setting == null)
             * {
             *  setting = new SettingEntity();
             *  createNew = true;
             * }
             *
             * setting.Key = model.Key;
             * setting.Value = model.Value;
             * if (createNew)
             * {
             *  if (_settingService.Create(setting).Id > 0)
             *  {
             *      return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功"));
             *  }
             * }
             * else
             * {
             *  if (_settingService.Update(setting) != null)
             *  {
             *      return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功"));
             *  }
             * }*/
            var settings = new List <SettingEntity>();

            foreach (var setting in model)
            {
                //Todo:效率过低,建议一次查询
                var newSet = _settingService.GetSettingByKey(setting.Key) ?? new SettingEntity {
                    Key = setting.Key
                };
                newSet.Value = setting.Value;
                settings.Add(newSet);
            }
            if (_settingService.CreateOrUpdateEntity(settings.ToArray()))
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功")));
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据更新失败")));
        }