Exemple #1
0
        public async Task Save(DictSaveInputDto saveDto)
        {
            if (string.IsNullOrWhiteSpace(saveDto.DictName))
            {
                throw new BusinessException(new ErrorModel(ErrorCode.BadRequest, "请输入字典名称"));
            }

            //add
            if (saveDto.ID == 0)
            {
                //long Id = new Snowflake(1, 1).NextId();
                long Id       = IdGeneraterHelper.GetNextId(IdGeneraterKey.DICT);
                var  subDicts = GetSubDicts(Id, saveDto.DictValues);
                await _dictRepository.InsertRangeAsync(subDicts.Append(new SysDict {
                    ID = Id, Pid = 0, Name = saveDto.DictName, Tips = saveDto.Tips, Num = "0"
                }));
            }
            //update
            else
            {
                var dict = new SysDict {
                    Name = saveDto.DictName, Tips = saveDto.Tips, ID = saveDto.ID, Pid = 0
                };
                var subDicts = GetSubDicts(saveDto.ID, saveDto.DictValues);
                await _maintManagerService.UpdateDicts(dict, subDicts);
            }
        }
Exemple #2
0
        public async Task <AppSrvResult> Update(DictSaveInputDto saveDto)
        {
            var exists = (await GetAllFromCache()).Exists(x => x.Name.EqualsIgnoreCase(saveDto.DictName) && x.ID != saveDto.ID);

            if (exists)
            {
                return(Problem(HttpStatusCode.BadRequest, "字典名字已经存在"));
            }

            var dict = new SysDict {
                Name = saveDto.DictName, Tips = saveDto.Tips, ID = saveDto.ID, Pid = 0
            };
            var subDicts = GetSubDicts(saveDto.ID, saveDto.DictValues);
            await _maintManagerService.UpdateDicts(dict, subDicts);

            return(DefaultResult());
        }
 public async Task Save(DictSaveInputDto saveDto)
 {
     //add
     if (saveDto.ID == 0)
     {
         //long Id = new Snowflake(1, 1).NextId();
         long Id       = IdGenerater.GetNextId();
         var  subDicts = GetSubDicts(Id, saveDto.DictValues);
         await _dictRepository.InsertRangeAsync(subDicts.Append(new SysDict {
             ID = Id, Pid = 0, Name = saveDto.DictName, Tips = saveDto.Tips, Num = "0"
         }));
     }
     //update
     else
     {
         var dict = new SysDict {
             Name = saveDto.DictName, Tips = saveDto.Tips, ID = saveDto.ID, Pid = 0
         };
         var subDicts = GetSubDicts(saveDto.ID, saveDto.DictValues);
         await _maintManagerService.UpdateDicts(dict, subDicts);
     }
 }