Ejemplo n.º 1
0
        public IActionResult Get(dynamic dynamicModel)
        {
            var response = new ResponseResult <DictTypeModel>();

            if (dynamicModel == null || dynamicModel.id < 1)
            {
                return(Ok(response.Error(ResponseCode.INVALID_PARAMS, "该数据不存在")));
            }
            int         id    = dynamicModel.id;
            SysDictType model = null;

            using (_dbContext)
            {
                model = _dbContext.SysDictType.SingleOrDefault(a => a.Id == id);
            }
            if (model == null)
            {
                return(Ok(response.Error(ResponseCode.ERROR_CODE__DB__NO_ROW, "该数据不存在")));
            }
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <int?, string>().ConvertUsing(new UtcStringTimeTypeConverter());
                cfg.CreateMap <DateTime?, string>().ConvertUsing(new UtcDateTimeTypeConverter());
                cfg.CreateMap <SysDictType, DictTypeModel>();
            });
            var data = model.MapTo <SysDictType, DictTypeModel>(mapConfig);

            return(Ok(response.Success("数据获取成功", data)));
        }
        public TableDataInfo <SysDictType> list(SysDictType dictType)
        {
            startPage(httpContextAccessor);
            long total = 1;
            List <SysDictType> list = dictTypeService.selectDictTypeList(dictType);

            return(getDataTable(list, total));
        }
Ejemplo n.º 3
0
        public TableData Query(SysDictType entity)
        {
            var result = new TableData();
            var data   = _app.Find(EntityToExpression <SysDictType> .GetExpressions(entity));

            GetData(data, result);
            result.count = data.Count();

            return(result);
        }
        public AjaxReponseBase edit([FromBody] SysDictType dict)
        {
            if (YouGeUserConstants.NOT_UNIQUE.Equals(dictTypeService.checkDictTypeUnique(dict)))
            {
                return(AjaxReponseBase.Error("修改字典'" + dict.DictName + "'失败,字典类型已存在"));
            }
            string username = SecurityUtils.getUsername(tokenService, httpContextAccessor.HttpContext.Request);

            dict.UpdateBy = username;
            return(toAjax(dictTypeService.updateDictType(dict)));
        }
 public string Upd(SysDictType Table_entity)
 {
     try
     {
         _app.Upd(Table_entity);
     }
     catch (Exception ex)
     {
         Result.Status  = false;
         Result.Message = ex.Message;
     }
     return(JsonHelper.Instance.Serialize(Result));
 }
Ejemplo n.º 6
0
        public ActionResult Edit(SysDictTypeViewModel viewModel)
        {
            if (ModelState.IsValid == false)
            {
                return(WriteError("实体验证失败"));
            }
            viewModel.Id           = viewModel.Id;
            viewModel.UpdateTime   = DateTime.Now;
            viewModel.UpdateUserId = UserManager.GetCurrentUserInfo().Id;
            SysDictType entity = viewModel.EntityMap();

            SysDictTypeService.Update(entity, new string[] { "Name", "Code", "SortCode", "UpdateTime", "UpdateUserId" });
            return(WriteSuccess());
        }
Ejemplo n.º 7
0
        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 }
            });
        }
        public string GetTemplate()
        {
            var result = new TableData();
            List <SysDictType> listSysDictType = new List <SysDictType>();
            SysDictType        entity          = _app.FindSingle(u => u.Id > 0);

            if (entity != null)
            {
                listSysDictType.Add(entity);
            }
            else
            {
                listSysDictType.Add(new SysDictType());
            }

            result.data  = listSysDictType;
            result.count = listSysDictType.Count;

            return(JsonHelper.Instance.Serialize(result));
        }
Ejemplo n.º 9
0
 public ActionResult Create(SysDictTypeViewModel viewModel)
 {
     try
     {
         if (ModelState.IsValid == false)
         {
             return(WriteError("实体验证失败"));
         }
         SysDictType entity = viewModel.EntityMap();
         entity.CreateUserId = UserManager.GetCurrentUserInfo().Id;
         entity.UpdateUserId = UserManager.GetCurrentUserInfo().Id;
         entity.CreateTime   = DateTime.Now;
         entity.UpdateTime   = DateTime.Now;
         SysDictTypeService.Add(entity);
         return(WriteSuccess());
     }
     catch (Exception ex)
     {
         return(WriteError(ex));
     }
 }
Ejemplo n.º 10
0
        public Response ImportIn(IFormFile excelfile)
        {
            Response           result    = new Infrastructure.Response();
            List <SysDictType> exp       = imp.ConvertToModel <SysDictType>(excelfile);
            string             sErrorMsg = "";

            for (int i = 0; i < exp.Count; i++)
            {
                try
                {
                    SysDictType e = exp[i];
                    e.Id = null;
                    _app.Add(e);
                }
                catch (Exception ex)
                {
                    sErrorMsg     += "第" + (i + 2) + "行:" + ex.Message + "<br>";
                    result.Message = sErrorMsg;
                    break;
                }
            }
            if (sErrorMsg.Equals(string.Empty))
            {
                if (exp.Count == 0)
                {
                    sErrorMsg     += "没有发现有效数据, 请确定模板是否正确, 或是否有填充数据!";
                    result.Message = sErrorMsg;
                }
                else
                {
                    result.Message = "导入完成";
                }
            }
            else
            {
                result.Status  = false;
                result.Message = result.Message;
            }
            return(result);
        }
Ejemplo n.º 11
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 }
            });
        }
        public AjaxReponseBase export(SysDictType dictType)
        {
            string rootpath = hostingEnvironment.WebRootPath + @"\ExcelFiles";

            if (!Directory.Exists(rootpath))
            {
                Directory.CreateDirectory(rootpath);
            }
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + dictType.DictType + ".xlsx";

            List <SysDictType> list = dictTypeService.selectDictTypeList(dictType);
            bool exportOK           = ExcelUtil.ExportExcelToFile <SysDictType>(list, "参数数据", null, rootpath, fileName);

            if (exportOK)
            {
                return(AjaxReponseBase.Success(fileName));
            }
            else
            {
                return(AjaxReponseBase.Error("导出失败!"));
            }
        }
 public string Load(PageReq pageRequest, SysDictType entity)
 {
     return(JsonHelper.Instance.Serialize(_app.Load(pageRequest, entity)));
 }
 public string Export(SysDictType entity)
 {
     return(JsonHelper.Instance.Serialize(_app.ExportData(entity)));
 }
Ejemplo n.º 15
0
 public TableData ExportData(SysDictType entity)
 {
     return(_app.ExportData(entity));
 }
Ejemplo n.º 16
0
 public static SysDictTypeViewModel EntityMap(this SysDictType model)
 {
     return(Mapper.Map <SysDictType, SysDictTypeViewModel>(model));
 }
Ejemplo n.º 17
0
 public TableData Load(PageReq pageRequest, SysDictType entity)
 {
     return(_app.Load(pageRequest, entity));
 }
Ejemplo n.º 18
0
 public void Upd(SysDictType entity)
 {
     _app.Update(entity);
 }
Ejemplo n.º 19
0
 public void Ins(SysDictType entity)
 {
     _app.Add(entity);
 }