Example #1
0
        public async Task <ActionResult <ResponseModel> > Create(DictionaryCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入字典名称");
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (_dbContext.SystemDictionary.Count(x => x.Name == model.Name) > 0)
                {
                    response.SetFailed("字典已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <DictionaryCreateViewModel, SystemDictionary>(model);
                entity.Code = RandomHelper.GetRandomizer(8, true, false, true, true);
                await _dbContext.SystemDictionary.AddAsync(entity);

                await _dbContext.SaveChangesAsync();

                //更新缓存
                _dictionaryService.ClearDictionaryCache();
                response.SetSuccess();
                return(Ok(response));
            }
        }
Example #2
0
        public ActionResult <ResponseModel> Create(DicTypeCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入字典类型名称");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (_dbContext.DncRole.Count(x => x.Name == model.Name) > 0)
                {
                    response.SetFailed("字典类型已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <DicTypeCreateViewModel, SystemDicType>(model);
                entity.Code = RandomHelper.GetRandomizer(8, true, false, true, true);
                _dbContext.SystemDicType.Add(entity);
                _dbContext.SaveChanges();
                //清理缓存
                _dictionaryService.ClearDictionaryCache();
                response.SetSuccess();
                return(Ok(response));
            }
        }