Exemple #1
0
        public IActionResult Create(DictTypeModel model)
        {
            var response = new ResponseResult <bool>();

            using (_dbContext)
            {
                if (_dbContext.SysDictType.Count(a => a.DictName == model.DictName) > 0)
                {
                    return(Ok(response.Error(ResponseCode.ERROR, "该名称已存在")));
                }
                if (_dbContext.SysDictType.Count(a => a.DictType == model.DictType) > 0)
                {
                    return(Ok(response.Error(ResponseCode.ERROR, "该标识已存在")));
                }
                var mapConfig = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <string, int?>().ConvertUsing(new NullableIntUtcTimeTypeConverter());
                    cfg.CreateMap <string, DateTime?>().ConvertUsing(new NullableUtcTimeTypeConverter());
                    cfg.CreateMap <DictTypeModel, SysDictType>();
                });
                //mapConfig.AssertConfigurationIsValid();
                var entity = model.MapTo <DictTypeModel, SysDictType>(mapConfig);
                _dbContext.Add(entity);
                int result = _dbContext.SaveChanges();
                if (result > 0)
                {
                    return(Ok(response.Success("数据提交成功", true)));
                }
                else
                {
                    return(Ok(response.Error(ResponseCode.ERROR, "数据提交失败")));
                }
            }
        }
Exemple #2
0
        private void HandleRequestData(DictTypeModel item, List <SysDictType> list)
        {
            if (item == null)
            {
                return;
            }
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <string, int?>().ConvertUsing(new NullableIntUtcTimeTypeConverter());
                cfg.CreateMap <string, DateTime?>().ConvertUsing(new NullableUtcTimeTypeConverter());
                cfg.CreateMap <DictTypeModel, SysDictType>();
            });
            //mapConfig.AssertConfigurationIsValid();
            var result = item.MapTo <DictTypeModel, SysDictType>(mapConfig);

            list.Add(result);
        }