Ejemplo n.º 1
0
        public async Task Save(CfgSaveInputDto inputDto)
        {
            //add
            if (inputDto.ID == 0)
            {
                var exist = await _cfgRepository.ExistAsync(c => c.CfgName == inputDto.CfgName);

                if (exist)
                {
                    throw new BusinessException(new ErrorModel(HttpStatusCode.BadRequest, "参数名称已经存在"));
                }

                var enity = _mapper.Map <SysCfg>(inputDto);

                //Vue处理大数字有问题,暂时不用Snowflake算法,以后完善。
                //enity.ID = new Snowflake(1, 1).NextId();
                enity.ID = IdGenerater.GetNextId();

                await _cfgRepository.InsertAsync(enity);
            }
            //update
            else
            {
                var exist = await _cfgRepository.ExistAsync(c => c.CfgName == inputDto.CfgName && c.ID != inputDto.ID);

                if (exist)
                {
                    throw new BusinessException(new ErrorModel(HttpStatusCode.BadRequest, "参数名称已经存在"));
                }

                var enity = _mapper.Map <SysCfg>(inputDto);

                await _cfgRepository.UpdateAsync(enity);
            }
        }
Ejemplo n.º 2
0
        public async Task <AppSrvResult> Update(CfgSaveInputDto inputDto)
        {
            var exist = (await this.GetAllFromCache()).Exists(c => c.CfgName.EqualsIgnoreCase(inputDto.CfgName) && c.ID != inputDto.ID);

            if (exist)
            {
                return(Problem(HttpStatusCode.BadRequest, "参数名称已经存在"));
            }

            var enity = _mapper.Map <SysCfg>(inputDto);
            await _cfgRepository.UpdateAsync(enity);

            return(DefaultResult());
        }
Ejemplo n.º 3
0
        public async Task <AppSrvResult <long> > Add(CfgSaveInputDto inputDto)
        {
            var exist = (await this.GetAllFromCache()).Exists(c => c.CfgName.EqualsIgnoreCase(inputDto.CfgName));

            if (exist)
            {
                return(Problem(HttpStatusCode.BadRequest, "参数名称已经存在"));
            }

            var cfg = _mapper.Map <SysCfg>(inputDto);

            cfg.ID = IdGenerater.GetNextId();

            await _cfgRepository.InsertAsync(cfg);

            return(cfg.ID);
        }
Ejemplo n.º 4
0
        public async Task <int> Save(CfgSaveInputDto inputDto)
        {
            if (string.IsNullOrWhiteSpace(inputDto.CfgName))
            {
                throw new BusinessException(new ErrorModel(ErrorCode.BadRequest, "请输入参数名称"));
            }

            if (string.IsNullOrWhiteSpace(inputDto.CfgValue))
            {
                throw new BusinessException(new ErrorModel(ErrorCode.BadRequest, "请输入参数值"));
            }

            //add
            if (inputDto.ID == 0)
            {
                var exist = await _cfgRepository.ExistAsync(c => c.CfgName == inputDto.CfgName);

                if (exist)
                {
                    throw new BusinessException(new ErrorModel(ErrorCode.BadRequest, "参数名称已经存在"));
                }

                var enity = _mapper.Map <SysCfg>(inputDto);

                //Vue处理大数字有问题,暂时不用Snowflake算法,以后完善。
                //enity.ID = new Snowflake(1, 1).NextId();
                enity.ID = IdGeneraterHelper.GetNextId(IdGeneraterKey.CFG);

                return(await _cfgRepository.InsertAsync(enity));
            }
            //update
            else
            {
                var exist = await _cfgRepository.ExistAsync(c => c.CfgName == inputDto.CfgName && c.ID != inputDto.ID);

                if (exist)
                {
                    throw new BusinessException(new ErrorModel(ErrorCode.BadRequest, "参数名称已经存在"));
                }

                var enity = _mapper.Map <SysCfg>(inputDto);

                return(await _cfgRepository.UpdateAsync(enity));
            }
        }
Ejemplo n.º 5
0
 public async Task Save([FromBody] CfgSaveInputDto saveDto)
 {
     await _cfgAppService.Save(saveDto);
 }
Ejemplo n.º 6
0
 public async Task <ActionResult <long> > Update([FromBody] CfgSaveInputDto saveDto)
 {
     return(Result(await _cfgAppService.Update(saveDto)));
 }
Ejemplo n.º 7
0
 public async Task <ActionResult <long> > Add([FromBody] CfgSaveInputDto saveDto)
 {
     return(CreatedResult(await _cfgAppService.Add(saveDto)));
 }