public async Task <AjaxResponse> SaveSysDictTypeModel(SysDictTypeInput model)
        {
            Guid?resId;

            //验证重复
            if (CheckDictCode(model))
            {
                return(new AjaxResponse {
                    Success = false, Error = new ErrorInfo("您设置的字典类型值" + model.DictType + "重复!")
                });
                //throw new UserFriendlyException("字典类型值重复", "您设置的字典类型值" + model.DictType + "重复!");
            }

            //新增或修改
            if (model.Id == null)
            {
                SysDictType modelInput = model.MapTo <SysDictType>();
                resId = await _sysDicTypetRepository.InsertAndGetIdAsync(modelInput);
            }
            else
            {
                //获取需要更新的数据
                SysDictType data = _sysDicTypetRepository.Get((Guid)model.Id);

                //映射需要修改的数据对象
                SysDictType m = ObjectMapper.Map(model, data);
                //提交修改
                await _sysDicTypetRepository.UpdateAsync(m);

                resId = model.Id;
            }

            //保存字典编码
            if (model.SysDictInputList != null)
            {
                AjaxResponse res = await _sysDictAppService.SaveSysDictModel(model.SysDictInputList);

                if (!res.Success)
                {
                    return(res);
                }
            }
            return(new AjaxResponse {
                Success = true, Result = new { id = resId }
            });
        }
示例#2
0
        public async Task <AjaxResponse> SaveSysDictTypeModel(SysDictTypeInput model)
        {
            Guid?resId;

            //验证重复
            if (CheckDictCode(model))
            {
                throw new UserFriendlyException("字典类型值重复", "您设置的字典类型值" + model.DictType + "重复!");
            }
            //新增或修改
            if (model.Id == null)
            {
                SysDictType modelInput = ObjectMapper.Map <SysDictType>(model);
                resId = await _sysDicTypetRepository.InsertAndGetIdAsync(modelInput);
            }
            else
            {
                //获取需要更新的数据
                SysDictType data = _sysDicTypetRepository.Get((Guid)model.Id);
                //映射需要修改的数据对象
                SysDictType m = ObjectMapper.Map(model, data);
                //提交修改
                await _sysDicTypetRepository.UpdateAsync(m);

                resId = model.Id;
            }
            //保存字典编码 (注释该段业务,保存字典类型的时候不保存对应的字典值明细数据,主要考虑页面操作习惯以及与明细自带的保存冲突问题)
            //if (model.SysDictInputList != null && model.SysDictInputList.Any())
            //{
            //    AjaxResponse res = await _sysDictAppService.SaveSysDictModel(model.SysDictInputList);
            //    if (!res.Success)
            //    {
            //        return res;
            //    }
            //}
            return(new AjaxResponse {
                Success = true, Result = new { id = resId }
            });
        }