public async Task <ActionResult <BaseResponse> > Add(int typeId, TypeConfigAddViewModel req) { string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; var rm = await _tc.AddAsync(typeId, req, Account); return(rm); }
public async Task <BaseResponse> AddAsync(int typeId, TypeConfigAddViewModel req, string account) { //验证类型是否可以添加 var t = await _tr.FindAsync(typeId); if (t.Status == TypeStatus.Root) { return(new BaseResponse { Success = false, Message = "目录节点类型不能添加具体数据" }); } //验证是否重名 var data = await _tc.Find(a => a.TypeId == typeId && a.DataName == req.DataName).FirstOrDefaultAsync(); if (data != null) { return(new BaseResponse { Success = true, Message = "已存在相同名称的类型配置,请确认" }); } try { var entity = _mapper.Map <TypeConfigModel>(req); entity.Create = account; entity.TypeId = typeId; await _tc.AddAsync(entity); _log.LogInformation($"{account}添加标示为{entity.Id}的类型配置数据成功"); return(new HandleResponse <int> { Success = true, Message = "添加类型配置数据成功", Key = entity.Id }); } catch (Exception ex) { _log.LogError($"{account}添加类型配置数据失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}"); return(new BaseResponse { Success = false, Message = "添加类型配置数据失败,请联系管理员" }); } }